Advertisement
jakaria_hossain

UVA-Goldbach's Conjecture

Sep 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement