Advertisement
CatalinCosmin

verificare element gresit

Dec 16th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int vPrim(int n)
  6. {
  7.     if(n==2 || n==5 || n==3) return 1;
  8.     if(n%2==0||n%5==0||n%3==0) return 0;
  9.     if(n>5)
  10.     {
  11.         if((n-1)%6==0)
  12.         {
  13.             if(int(sqrt(n))!=sqrt(n)) return 1;
  14.         }
  15.         else if((n+1)%6==0)
  16.             if(int(sqrt(n))!=sqrt(n)) return 1;
  17.     }
  18.     return 0;
  19. }
  20.  
  21. int vPrim2(int n)
  22. {
  23.     if(n<2) return 0;
  24.     if(n==2) return 1;
  25.     if(n%2==0) return 0;
  26.     for(int d=3;d*d<=n;d+=2)
  27.         if(n%d==0) return 0;
  28.     return 1;
  29. }
  30.  
  31. int main()
  32. {
  33.     int n, i;
  34.     cin >> n;
  35.     for(i=0;i<=n;++i)
  36.     {
  37.         if(i==1000000||i==10000000||i==100000000||i==500000000||i==800000000) cout << "acum: nr = " << i << " \n";
  38.         if(vPrim(i)!=vPrim(i))
  39.             cout << i << " e gresit \n";
  40.         if(i==n) cout << "Am ajuns la n \n";
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement