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;
}
}
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
ReplyDeleteWa alaykumu s-salam ,amar jono dowa koren vai.
Delete