daily pastebin goal
27%
SHARE
TWEET

Tamas

a guest Dec 10th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int Prim(int n)
  7. {
  8.     if (n<2)
  9.         return 0;
  10.     if (n==2)
  11.         return 1;
  12.     if (n%2==0)
  13.         return 0;
  14.     for(int d=3;d<=sqrt(n);d=d+2)
  15.         if(n%d==0)
  16.             return 0;
  17.     return 1;
  18. }
  19.  
  20. int Osszeg(int x)
  21. {
  22.     int s=0;
  23.     while (x>0)
  24.     {
  25.         s=s+x%10;
  26.         x=x/10;
  27.     }
  28.     return s;
  29.  
  30. }
  31.  
  32. int main()
  33. {
  34.     unsigned n,m;
  35.     cout<<"N=";
  36.     cin>>n;
  37.     cout<<"M=";
  38.     cin>>m;
  39.     int db=0;
  40.     int x=2;
  41.     while (db<n)
  42.     {
  43.         if (Prim(x) && Osszeg(x)<m)
  44.         {
  45.             cout<<x<<" ";
  46.             db++;
  47.         }
  48.         x++;
  49.     }
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top