Advertisement
momo2345

gold batch's problem

Nov 3rd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. using namespace __gnu_pbds;
  6. typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
  7. #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  8. #define endl "\n"
  9. #define mn int main()
  10. #define frac() cout.unsetf(ios::floatfield);cout.precision(6);cout.setf(ios::fixed,ios::floatfield);
  11.  
  12.  
  13. const int mx=1e6+123;
  14. bool  isprime[mx];
  15. vector<int>prime;
  16. void primegen(int n){
  17.     memset(isprime,1,sizeof(isprime));
  18.     isprime[1]=0;
  19.     for(int i=2;i<=n;i++){
  20.         for(int j=i+i;j<=n;j+=i)
  21.             isprime[j]=0;
  22.     }
  23.     for(int i=3;i<=n;i++){
  24.         if(isprime[i]) prime.push_back(i);
  25.     }
  26. }
  27.  mn
  28. {
  29.     suni;
  30.     primegen(1e6);
  31.     int n;
  32.     while(cin>>n){
  33.         if(n==0) break;
  34.         int p1=-1,p2=-1;
  35.         for(auto u: prime){
  36.          if(u>n) break;
  37.           int tp1=u,tp2=n-u;
  38.           if(tp2>2 && isprime[tp2]==1){
  39.              p1=tp1;
  40.              p2=tp2;
  41.              break;
  42.           }
  43.         }
  44.         cout<<n<<" = "<<p1<<" + "<<p2<<endl;
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement