Saleh127

uva 10311.cpp

Jun 8th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5. #define maX 100000002
  6. bool pm[maX];
  7. void sieve()
  8. {
  9. pm[2]=false;
  10. for(ll i=4;i<=100000000;i+=2)
  11. {
  12. pm[i]=true;
  13. }
  14. for(ll i=3;i<=100000000;i+=2)
  15. {
  16. if(!pm[i])
  17. {
  18. for(ll j=i*i;j<=100000000;j+=i+i)
  19. {
  20. pm[j]=true;
  21. }
  22. }
  23. }
  24. pm[0]=pm[1]=true;
  25. }
  26. int main()
  27. {
  28. Faster
  29. sieve();
  30. ll a,c,i,j,k,l;
  31. while(scanf("%lld",&a)==1)
  32. {
  33. k=0;
  34. if(a%2==1)
  35. {
  36. c=a-2;
  37. if(!pm[c] && c>2)
  38. {
  39. printf("%lld is the sum of 2 and %lld.\n",a,c);
  40. }
  41. else
  42. {
  43. printf("%lld is not the sum of two primes!\n",a);
  44. }
  45. }
  46. else
  47. {
  48. for(i=a/2+1;i<a;i++)
  49. {
  50. c=a-i;
  51. if(!pm[i] && !pm[c] && i-c>0)
  52. {
  53. k=1;
  54. printf("%lld is the sum of %lld and %lld.\n",a,c,i);
  55. break;
  56. }
  57. }
  58. if(k==0)
  59. {
  60. printf("%lld is not the sum of two primes!\n",a);
  61. }
  62. }
  63.  
  64. }
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment