Hdu_5778_abs (violence)

Source: Internet
Author: User

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)

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.