LightOj 1078 Integer Divisibility






Hints:  long long int can not contain such a big type of data as there may be 10^6 digit. string or char data type can contain but you will get time limit exceed as you need to process loop 10^6*10^6=10^12 times. so simply check divisibility digit by digit such as if input is 3 1 then number is=111 . so at first check 1 then 11 and last 111. that remainder r can be checked by this rule (if n is 3 and m is 1) r=(r*10+m)%n



#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("id.txt","r",stdin);
    //freopen("idout.txt","w",stdout);
    long long int i,j,n,t,l,z,m,k,r;
    string s;
    cin>>t;
    for(i=1;i<=t;i++)
    {
        cin>>n>>m;
        r=0;
        l=0;
        for(j=0;j<n;j++)
        {
            r=(r*10+m)%n;
            l++;
            if(r==0)
            {
                break;
            }
        }
        printf("Case %lld: %lld\n",i,l);






    }
    return 0;
}






Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment