1214 - Large Division -- LightOj(大数取余)

http://lightoj.com/volume_showproblem.php?problem=1214

这就是一道简单的大数取余。

还想还用到了同余定理:

所谓的同余,顾名思义,就是许多的数被一个数d去除,有相同的余数。d数学上的称谓为模。如a=6,b=1,d=5,则我们说a和b是模d同余的。因为他们都有相同的余数1。

////

数学上的记法为:

a≡ b(mod d)

可以看出当n<d的时候,所有的n都对d同商,比如时钟上的小时数,都小于12,所以小时数都是模12的同商.

对于同余有三种说法都是等价的,分别为:

(1) a和b是模d同余的.

(2) 存在某个整数n,使得a=b+nd .

(3) d整除a-b.

可以通过换算得出上面三个说法都是正确而且是等价的.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
typedef long long LL;
#define N 100000
#define ESP 1e-8
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))

int main()
{
    int T, t=1;
    scanf("%d", &T);
    while(T --)
    {
        char s[300];
        LL b;
        scanf("%s %lld", s, &b);
        if(b < 0)
            b = -b;

        printf("Case %d: ", t++);

        int len = strlen(s);
        if(len == 1 && s[0] == ‘0‘)
        {
            printf("divisible\n");
            continue;
        }

        LL sum = 0;
        for(int i=0; i<len; i++)
        {
            if(s[i] == ‘-‘)
                continue;

            sum = sum*10 + s[i]-‘0‘;
            sum = sum%b;
        }

        if(sum == 0)
            printf("divisible\n");
        else
            printf("not divisible\n");
    }
    return 0;
}
时间: 2024-08-07 08:40:28

1214 - Large Division -- LightOj(大数取余)的相关文章

LightOJ 1214 - Large Division (大数取余)

1214 - Large Division PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given two integers, a and b, you should checkwhether a is divisible by b or not. We know that an integer ais divisible by an integer b if and only if the

大数模拟——K - Large Division LightOJ - 1214

K - Large Division LightOJ - 1214 大数模拟,记得把符号去掉 1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <set> 6 #include <algorithm> 7 #include <fstream> 8 #include <cstdio>

light oj 1214 - Large Division 大数除法

1214 - Large Division 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. Input Input starts with an in

LightOJ 1214(Large Division)

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. Input Input starts with an integer T (≤ 525), denot

light oj 1214 - Large Division

1214 - Large Division   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB 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

LightOJ - 1214 Large Division(同余)

Large Division Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description 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

sum 大数取余+快速幂

Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3980    Accepted Submission(s): 1620 Problem Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input fil

LightOJ1214 Large Division 基础数论+同余定理

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. Input Input starts with an integer T (≤ 525), denot

hdoj-1212-Big Number【大数取余&amp;简单题】

Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6015 Accepted Submission(s): 4205 Problem Description As we know, Big Number is always troublesome. But it's really important in our ACM.