Advertisement
leminhkt

noname12 (NUMBER)

Mar 2nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define pub(a, x) (a).push_back(x)
  4. using namespace std;
  5. void update(ll* n){
  6.     *n=(*n<4)?((*n==2)?3:5):((*n-1)%6)?(*n+2):(*n+4);
  7. }
  8. bool cprm(ll n){
  9.     if(n==2||n==3) return 1;
  10.     if(n%2==0||n%3==0||n<2) return 0;
  11.     for(ll i=5; i<=sqrt(n); update(&i)) if(n%i==0) return 0;
  12.     return 1;
  13. }
  14. vector<ll> a={0}, b={0};
  15. ll inp, n=1;
  16. int main(){
  17.     freopen("NUMBER.inp", "r", stdin);
  18.     freopen("NUMBER.out", "w", stdout);
  19.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  20.     cin>>inp;
  21.     pub(b, cprm(inp));
  22.     while(cin>>inp){
  23.         n++;
  24.         if(cprm(inp)){
  25.             pub(b, 1);
  26.             if(b[n-2]){
  27.                 cout<<n-1;
  28.                 return 0;
  29.             }
  30.         }
  31.         else pub(b, 0);
  32.     }
  33.     cout<<0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement