Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int Prim(int n)
- {
- if (n<2)
- return 0;
- if (n==2)
- return 1;
- if (n%2==0)
- return 0;
- for(int d=3;d<=sqrt(n);d=d+2)
- if(n%d==0)
- return 0;
- return 1;
- }
- int Osszeg(int x)
- {
- int s=0;
- while (x>0)
- {
- s=s+x%10;
- x=x/10;
- }
- return s;
- }
- int main()
- {
- unsigned n,m;
- cout<<"N=";
- cin>>n;
- cout<<"M=";
- cin>>m;
- int db=0;
- int x=2;
- while (db<n)
- {
- if (Prim(x) && Osszeg(x)<m)
- {
- cout<<x<<" ";
- db++;
- }
- x++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement