Light OJ 1035 Intelligent Factorial Factorization Solution

   ///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    Solution in c++:

    #include <bits/stdc++.h>
    using namespace std;
    #define max 10009
    int a[max],ar[max];
    int prime[max];
    int main()
    {
        int t,n,i,k,count=0,j,temp,c=0,v,lastprime;
        for(i=3; i<=sqrt(max); i+=2)
        {
            if(a[i]==0)
            {
              for(j=i*i; j<=max; j+=i)
                {
                    a[j]=1;
                }
            }
        }
        prime[count++]=2;
        for(i=3; i<=max; i+=2)
        {
            if(a[i]==0)
            {
                prime[count++]=i;
            }
        }
        cin>>t;
        for(k=1; k<=t; k++)
        {  c=0;
            cin>>n;
            for(i=0; prime[i]<=n; i++)
            {
                temp=n;
                v=0;
                while(temp!=0)
                {
                    v+=temp/prime[i];
                    temp/=prime[i];
                }
                ar[c]=v;
                c++;
            }
            lastprime=prime[i-1];
            printf("Case %d: %d = ",k,n);
            for(j=0;prime[j]<=n;j++)
            {
                printf("%d (%d)",prime[j],ar[j]);
                if(prime[j]<lastprime)
                {
                    printf(" * ");
                }
            }
            cout<<endl;
        }
    }



    2 comments:

    1. via assalmulaikum.................. apnar code golo pore onk valo laglo . apnr ekhane ekta jinish dekhe ami onk obak hoi gelam ......... mashallah isllam ke apni onk opore tular try kortechen. asha kore allah o apnk ei vabe opore tule dibo

      ReplyDelete
      Replies
      1. Wa alaykumu s-salam ,amar jono dowa koren vai.

        Delete

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

    Powered by Blogger.