LightOJ

链接:

https://vjudge.net/problem/LightOJ-1214

题意:

Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if there exists an integer c such that a = b * c.

思路:

考虑同余式 ((a ast 10) \% m + b \% m = a \% m)

链接:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>

using namespace std;
typedef long long LL;
const int INF = 1e9;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;

char s[500];

int main()
{
    int t, cnt = 0;
    LL mod;
    scanf("%d", &t);
    while(t--)
    {
        printf("Case %d: ", ++cnt);
        scanf("%s %lld", s, &mod);
        mod = abs(mod);
        LL m = (s[0] != '-')?(s[0]-'0'):(s[1]-'0');
        int len = strlen(s);
        for (int i = (s[0] != '-')?1:2;i < len;i++)
            m = (m*10%mod+(s[i]-'0'))%mod;
        if (m == 0)
            puts("divisible");
        else
            puts("not divisible");
    }

    return 0;
}
原文地址:https://www.cnblogs.com/YDDDD/p/11841216.html