Title Link: hdu_5778_abs
Test instructions
Give you a number x, then you find a Y, this y can only be broken down by prime numbers, each prime is exactly 2 times, to find the absolute value of y-x minimum
Exercises
To the official PS: Data too water, hit 35 primes can also
1#include <bits/stdc++.h>2 #defineF (I,A,B) for (int i=a;i<=b;++i)3 using namespacestd;4typedefLong Longll;5 Const inte_n= *;6 intP[e_n],tot;7 BOOLvis[e_n+1];8 voidEuler () {9F (I,2, E_n) {Ten if(!vis[i]) p[++tot]=i; OneF (J,1, tot) { A if(I*p[j]>e_n) Break; -vis[i*p[j]]=1; - if(i%p[j]==0) Break; the } - } - } - + BOOLCheckintx) - { + for(intI=1; i<=tot&&p[i]*p[i]<x;i++)if(x%p[i]==0) A { atX/=P[i]; - if(x%p[i]==0)return 0; - } - return 1; - } - in intMain () { - Euler (); to intT;SCANF ("%d",&t); + while(t--) - { the ll N,ans; *scanf"%lld",&n); $ inttmp= (LL) sqrt (n+0.5);Panax Notoginseng if(tmp<2) {printf ("%lld\n", 4ll-n);Continue;} - for(inti=tmp;i>=2; i--) the if(check (i)) {ans=abs (1ll*i*i-n); Break;} + for(inti=tmp+1;; i++) A if(check (i)) {Ans=min (Ans,abs (1ll*i*i-n)); Break;} theprintf"%lld\n", ans); + } - return 0; $}
View Code
Hdu_5778_abs (violence)