Analysis: Y is a square with no squared factor number, so you can find the first non-squared factor comparison size from sqrt (x) up-down enumeration
You may feel like this to find past violence, but in fact no square factor of distributed very dense, related topics, you can refer to
CDOJ: No square factor number http://acm.uestc.edu.cn/#/problem/show/618
This problem and cdoj, although different, but can be found from cdoj this number is a lot of
Official puzzle: The official explanation is that this square-free enumerator is at the Logn level and is very small.
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<vector>using namespaceStd;typedefLong LongLL;Const intN = 1e5+5;BOOLV[n];intPrime[n>>1],cnt;voidGetprime () { for(intI=2; i*i<=n-5;++i)if(!V[i]) for(intj=i*i;j<=n-5; j+=i) v[j]=1; for(intI=2; i<=n-5;++i)if(!v[i]) prime[++cnt]=i;} ll Fun (ll X,ll y) {if(x>y) Swap (x, y); returnY-x;}intMain () {intT; Getprime (); scanf ("%d",&T); while(t--) {LL n;scanf ("%i64d",&N); LL x= (LL) (sqrt (1.0*n) +0.5), l=-1, r=-1; for(intk=x;k>=2;--k) { BOOLflag=false; for(intI=1; i<=cnt&&1ll*prime[i]*prime[i]<=k;++i) { if(k% (1ll*prime[i]*prime[i]) = =0) {flag=true; Break;} } if(!flag) {l=k; Break;} } for(intk=x+1;; ++k) { BOOLflag=false; for(intI=1; i<=cnt&&1ll*prime[i]*prime[i]<=k;++i) { if(k% (1ll*prime[i]*prime[i]) = =0) {flag=true; Break;} }if(!flag) {r=k; Break;} } LL ret; if(l==-1) Ret=fun (r*r,n); ElseRet=min (N,l*l), Fun (r*r,n)); printf ("%i64d\n", ret); } return 0;}
View Code
HDU 5578 ABS (Bestcoder Round #85 C) prime Sieve + violence