Spoj FACT0 - Integer Factorization (15 digits) Solution




Problem Link:  https://www.spoj.com/problems/FACT0/ 

 Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
void factorize(long long n)
{
    int count = 0;
    while (!(n % 2))
    {
        n >>= 1;
        count++;
    }
 
    if (count)
        cout<<"2^"<<count<<" ";
 
    for (long long i = 3; i <= sqrt(n); i += 2)
    {
        count = 0;
        while (n % i == 0)
        {
            count++;
            n = n / i;
        }
        if (count)
            cout<<i<<"^"<<count<<" ";
    }
    if (n > 2)
        cout<<n<<"^1"<<endl;;
}
 
int main()
{
    long long n;
    while(cin>>n)
    {
        if(n==0)
            break;
        factorize(n);
    }
      return 0;
}
  








No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.