Saturday 26 March 2016

Solution of LIGHT OJ 1214 :: Large Division


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahimm**/

#include <stdio.h>
int main()
{
    long long int tst, i, j, b, dcml;
    char a[1000];
    scanf("%lld", &tst);
    for(i=1; i<=tst; i++)
    {
        long long int mod_a=0, div_a=0;
        scanf("%s", a);
        scanf("%lld", &b);
        j=0;
        if(a[0]=='-') j=1;
        while(a[j])
        {
            dcml = a[j] - 48;
            div_a+=dcml;
            mod_a = div_a%b;
            div_a= mod_a*10;
            j++;
        }
        if(mod_a==0) printf("Case %lld: divisible\n", i);
        else printf("Case %lld: not divisible\n", i);
    }
    return 0;
}

5 comments:

  1. I didn't understand the while loop

    ReplyDelete
  2. Here while(a[j]) means this while loop will continue until the string a[1000] finish.

    ReplyDelete
  3. Can you explain the algorithm?

    ReplyDelete
  4. Can you provide some resource about this logic.

    ReplyDelete

Note: only a member of this blog may post a comment.