Advertisement
allia

простое разложение числа

Sep 12th, 2020
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  int function2 (int a, int i, int p)
  6.  {
  7.       while (a%i==0)
  8.        {
  9.          a/=i;
  10.          p++;
  11.          function2(a, i, p);
  12.        }
  13.     return p;
  14.  }
  15.  int main ()
  16.  {
  17.    int a=0, c=0, p=0, n=1;
  18.    cin >> a;
  19.    c=a;
  20.    
  21.  int arr[2][c];
  22.  for (int i=0; i<2; i++)
  23.      for (int j=0; j<c-1; j++)
  24.        arr[i][j]=0;
  25.  
  26.      for (int j=0; j<c-1; j++)
  27.       {
  28.         if (a%(j+2)==0)
  29.          {
  30.            arr[0][j]=j+2;
  31.            arr[1][j]=function2(a,j+2,p);
  32.            a/=pow(j+2, arr[1][j]);
  33.          }
  34.          p=0;
  35.       }
  36.  
  37.   for (int i=0; i<2; i++)
  38.    {
  39.      for (int j=0; j<c-1; j++)
  40.      {
  41.        cout.width(3);
  42.        if (arr[0][j]!=0)
  43.        cout << arr[i][j] << " ";
  44.      }
  45.      cout << endl;
  46.    }
  47.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement