ValerianBenchea

Suma divizorilor primi ai unui nr.

Jan 15th, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, d, p=0, i, s=0;
  7.     cout<<"n="; cin>>n;
  8.     for(d=2; d<=n/2; d++)
  9.     {
  10.         if(n%d==0)
  11.         {
  12.             p=0;
  13.             for(i=2; i<=d/2; i++)
  14.             {
  15.                 if(d%i==0)
  16.                     p++;
  17.             }
  18.              if(p==0)
  19.              {
  20.                     s=s+d;
  21.                     cout<<d<<" ";
  22.              }
  23.         }
  24.     }
  25.      cout<<"Suma divizorilor primi este "<<s;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment