jakaria_hossain

UVA-Goldbach's Conjecture

Sep 24th, 2018
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. vector<bool>is_prime(1000000,true);
  5. int main()
  6. {
  7. int i,j,n;
  8. for(i=2; i<=sqrt(1000000); i++)
  9. {
  10. if(is_prime[i])
  11. {
  12. for(j=i*i; j<=1000000; j+=i)
  13. is_prime[j]=false;
  14. }
  15. }
  16.  
  17. while(scanf("%d",&n))
  18. {
  19. if(n==0)
  20. break;
  21.  
  22.  
  23. for(i=3; i<n/2+1; i+=2)
  24. {
  25. if(is_prime[i])
  26. {
  27. if(is_prime[n-i])
  28. {
  29. printf("%d = %d + %d\n",n,i,n-i);
  30. break;
  31. }
  32. }
  33. }
  34. if(i>n/2+1)
  35. printf("Goldbach's conjecture is wrong.\n");
  36.  
  37. }
  38. return 0;
  39. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×