Advertisement
Dani_info

pb 1-5

Dec 7th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6.  
  7. {   int pb;
  8.     cout<<"Introduceti numarul problemei:"; cin>>pb;
  9.     switch(pb)
  10.     {
  11. case 5:
  12.     {
  13.     int n, x, i, j, d, cnt;
  14.     cout<<"Cate numere sa se citeasca??"<<endl;  cin>>x;
  15.     for(i=1; i<=x; i++)
  16.     {   cnt=0;
  17.         cout<<"n=";  cin>>n;
  18.         for(j=1; j<=n; j++)
  19.         {
  20.             d=n%j;
  21.             if(d==0 && j%2==0)
  22.                {cout<<j<<endl;
  23.                 cnt=cnt+1;
  24.                }
  25.  
  26.         }
  27.         if(cnt==0)
  28.                 cout<<"Nu exista divizori pari"<<endl;
  29.  
  30.     }
  31.     } break;
  32.     case 4:
  33.         {
  34.             int p, x, n, cnt=0;
  35.             cout<<"Introduceti un nr prim:"; cin>>p;
  36.             while(n!=0)
  37.             {
  38.                 cout<<"n="; cin>>n;
  39.                 while(n>=p && n%p==0)
  40.                 {
  41.                     n=n/p;
  42.                     cnt=cnt+1;
  43.  
  44.                 }
  45.  
  46.  
  47.             }
  48.             cout<<"Putere maxima a lui "<<p<<" este: "<<cnt;
  49.         }
  50.         break;
  51.     case 3:
  52.         {
  53.             int a, b, x, y, k;
  54.             float x2, y2;
  55.             cin >> k; // a * b = k // a = x + y // b = x - y
  56.             for (int i = 1; i <= k/2; i++)
  57.             {
  58.                 if (k%i == 0)
  59.                 {
  60.                     a = i;
  61.                     b = k / a;
  62.                     x = (a + b) / 2;
  63.                     x2 = ((float)a + b) / 2;
  64.                     y = (a - b) / 2;
  65.                     y2 = ((float)a - b) / 2;
  66.                     if (x >= 0 && y >= 0 && x == x2 && y == y2)
  67.                     {
  68.                         cout << a << '*' << b << " = " << k << endl; // a*b = k
  69.                         cout << x << "^2" << " - " << y << "^2" << " = " << k << endl; // x^2 - y^2 = k
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.     break;
  75.  
  76.     }
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement