Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream f("fantastice.in");
- ofstream g("fantastice.out");
- int nr_div(int n)
- {
- int i,nr=0;
- for(i=1;i*i<n;i++)
- if(n%i==0)
- nr+=2;
- if (i*i==n)
- ++nr;
- return nr;
- }
- bool prim(int n)
- {
- if(n<2)
- return false;
- ///numerele pare mai mari decat 2 nu sunt prime
- if(n % 2 == 0 && n > 2)
- return false;
- bool eprim=true;/// Presupunem ca e prim
- ///cautam un divizor impar
- for(int d=3;d*d<=n&&eprim;++d)
- if(n%d==0) /// daca il gasim
- eprim=false; ///numarul n nu este prim
- if(eprim)
- return true;
- else
- return false;
- }
- int main()
- {
- int n,x,fantastice=0;
- f>>n;
- while(n--)
- {
- f>>x;
- if(prim(x))
- ++fantastice;
- else
- if(prim(nr_div(x)))
- ++fantastice;
- }
- g<<fantastice;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement