Light OJ 1028 - Trailing Zeroes (I) Solution

if you don't know ,how to the Finding Number of Divisors

please reading this toutorial:

1)Finding Number of Divisors(Bangla))

2)Finding Number of Divisors(English)

  Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh  

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define n 1000009
  4. bool a[n];
  5. long long int i,j,k=1;
  6. long long int d[n];
  7. void sieve()
  8. {
  9.  
  10.     a[0]=a[1]=1;
  11.     for(i=4; i<=n; i=i+2)
  12.     {
  13.         a[i]=1;
  14.     }
  15.  
  16.     for(i=3;i<=sqrt(n);i=i+2)
  17.     {
  18.         for(j=i*i;j<=n;j=j+2*i)
  19.         {
  20.             a[j]=1;
  21.         }
  22.     }
  23.     for(i=2; i<=n; i++)
  24.     {
  25.         if(a[i]==0)
  26.         {
  27.             d[k]=i;
  28.             k++;
  29.         }
  30.     }
  31.  
  32. }
  33. int main()
  34. {
  35.     long long int v,r,q,p,cnt,x,m,t;
  36.     cin>>t;
  37.     sieve();
  38.     for(m=1; m<=t; m++)
  39.     {
  40.         cin>>v;
  41.         r=1;
  42.         for(p=1; p<=k&&d[p]<=sqrt(v); p++)
  43.         {
  44.             cnt=0;
  45.             if(v%d[p]==0)
  46.             {
  47.                 while(v%d[p]==0)
  48.                 {
  49.                     cnt++;
  50.                     v=v/d[p];
  51.                     if(v==0||v==1)
  52.                         break;
  53.                 }
  54.                 x=cnt+1;
  55.                 r=r*x;
  56.             }
  57.         }
  58.         if(v!=1)
  59.         {
  60.             r=r*2;
  61.         }
  62.         printf("Case %lld: %lld\n",m,r-1);
  63.     }
  64. }
  65.  

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.