Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n,x,i,d,c;
- int s;
- bool ok;
- cin>>n; ///nr de elemente
- s=0;
- for(int i=1;i<=n;i++)
- {
- cin>>x;///valoarea citita
- ok=1; /// am presuspus ca x este prim
- if(x<2) ok=0;
- else
- {
- for(d=2;d*d<=x && ok==1;d++)
- if(x%d==0)ok=0;
- }
- if(ok==1)
- {
- while(x!=0)
- {
- c=x%10;
- x=x/10;
- s+=c;
- }
- }
- }
- cout<<s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment