Advertisement
rotti321

SIII ex1 simulare 2021

Jan 15th, 2022
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int putere(int n){
  5.     int p,d=2,pmin=1000000,sol=0;
  6.     while (n!=1)
  7.     {
  8.       p=0;
  9.       while (n%d==0)
  10.       {
  11.           n=n/d;
  12.           p++;
  13.           //construim d ^ p
  14.       }
  15.       if(p!=0 && p<pmin){
  16.           pmin=p;
  17.           sol=d;
  18.       }
  19.       d++;
  20.   }
  21.   return sol;
  22. }
  23. int main()
  24. {
  25.   int n;
  26.   cin>> n;
  27.   cout<<putere(n);
  28.   return 0;
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement