首页 > 其他 > 详细

LightOJ - 1214-Large Division(数学,同余)

时间:2019-11-12 14:45:30      阅读:70      评论:0      收藏:0      [点我收藏+]

链接:

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;
}

LightOJ - 1214-Large Division(数学,同余)

原文:https://www.cnblogs.com/YDDDD/p/11841216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!