题目:Large Division   LightOJ - 1214 

题解:该题就是大整数进行取模

参考博客:https://blog.csdn.net/ramay7/article/details/51531215

代码:

#include<bits/stdc++.h>
using namespace std;
#define LL long long
char a[205];
int main(){
    int T;
    scanf("%d", &T);
    int ca = 0;
    while(T--){
        getchar();
        LL n;
        scanf("%s %lld", a, &n);
        int len = strlen(a);
        //cout<<len<<endl;
        printf("Case %d: ", ++ca);
        if(a[0] == '0' && len == 1){
                printf("divisible\n");
                continue;
        }
        if(n < 0)n = -n;
        LL ans = 0;
        int i = 0;
        if(a[0] == '-')i = 1;
        for(; i < len; i++){
            ans  = (ans*10+a[i]-'0')%n;
        }
        if(ans == 0)printf("divisible\n");
        else printf("not divisible\n");
    }
return 0;
}

 

posted on 2019-04-06 19:52  Refused  阅读(42)  评论(0)    收藏  举报