LightOj 1028 - Trailing Zeroes (I)
[ ট্রায়ালিং জিরো বলতে আমি যা বুঝলাম, কোন একটা সংখ্যাকে এমন কোন সংখ্যা দিয়ে ভাগ করলে তার ভাগফল জিরো হবে । এবং ওই সংখ্যাটাই হবে তার বেইস । ]
[ A number you will get mod zero to divide another number. Then, that number will be the base of 1st number....]
formula:: 9=3*3; (x+1)*(y+1)=(0+1)*(2+1)=3; where, x and y is the power of 2 and 3. Then the result is = 3-1=2; so, again, x,y,z are represented bt the power of 2,3 and 5.....
/*
LightOj 1028 - Trailing Zeroes (I)
Verdict :: Accepted
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf ("%d %d",&a,&b)
#define sfl scanf ("%ld %ld",&a,&b)
#define sfll scanf ("%lld %lld",&a,&b)
#define sfd scanf ("%lf %lf",&a,&b)
#define sff scanf ("%f %f",&a,&b)
#define loop(i,n) for(i=0;i<n;i++)
#define LL long long
#define L long
#define nl puts("")
#define MX 1000005
#define N 100
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define bn begin()
#define ed end()
using namespace std;
bool flag[MX];
vector<int>v;
int v_len;
void prime()
{
int i,j,qrt;
for (i=4;i<=MX;i+=2)
{
flag[i]=true;
}
v.push_back(2);
qrt=(int) sqrt(double(MX));
for(i=3;i<=qrt;i+=2)
{
if (!flag[i])
{
for(j=i*i;j<=MX;j+=i+i)
{
flag[j]=true;
}
}
}
for(i=3;i<=MX;i+=2)
{
if(!flag[i])
{
v.push_back(i);
}
}
v_len=v.size();
}
LL primefacto(LL n)
{
LL i,s,m=1,k;
for(i=0;i<v_len and v[i]*v[i]<=n;i++)
{
k=0;
if(n%v[i]==0)
{
while(n%v[i]==0)
{
k+=1;
n/=v[i];
if(n==0 or n==1) break;
}
s=k+1;
m*=s;
}
}
if(n != 1) m*=2;
return (m);
}
int main()
{
int t,tc,i;
prime();
//loop(i,v_len)cout<<v[i] << " ";
sf("%d",&tc);
loop(t,tc)
{
LL n;
sf("%lld",&n);
LL r=primefacto(n)-1;
pf("Case %d: %lld\n",t+1,r);
}
return 0;
}
can u explain for which u use this . if(n != 1) m*=2;
ReplyDeletejodi n=5 hoy tahole sqrt of 5 = 2 hobe shekhetre m=0 paben tai n=5 e thake jabe.
Deletethen ei condition ta kaje lagbe, karon tokhon 5^1 hobe prime factorization ar number of divisors hobe 1+1=2.
jehetu 1 divisor ti ei solution e lagbe na tai m=2-1=1 hobe.:)