Advertisement
sajid161

Class - 27 : Task - 1

Jan 19th, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int prime_factor(int n)
  4. {
  5.     cout<<n<<" = ";
  6.     int ans=0;
  7.     if(n<0)
  8.     {
  9.         n=-n;
  10.         cout<<-1<<" x ";
  11.     }
  12.     for(int i=2;i*i<=n;i++)
  13.     {
  14.         if(n%i==0)
  15.         {
  16.             while(n%i==0)
  17.             {
  18.                 n/=i;
  19.                 cout<<i<<" x ";
  20.             }
  21.  
  22.         }
  23.     }
  24.  
  25.         if(n>1) cout<<n;
  26.  
  27.  
  28. }
  29. int main()
  30. {
  31.     int n;
  32.     while(cin>>n)
  33.     {
  34.         if(n==0) break;
  35.         prime_factor(n);
  36.         cout<<endl;
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement