zoukankan      html  css  js  c++  java
  • LightOJ1214 Large Division —— 大数求模

    题目链接:https://vjudge.net/problem/LightOJ-1214

    1214 - Large Division
    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 there exists an integer c such that a = b * c.

    Input

    Input starts with an integer T (≤ 525), denoting the number of test cases.

    Each case starts with a line containing two integers a (-10200 ≤ a ≤ 10200) and b (|b| > 0, b fits into a 32 bit signed integer). Numbers will not contain leading zeroes.

    Output

    For each case, print the case number first. Then print 'divisible' if a is divisible by b. Otherwise print 'not divisible'.

    Sample Input

    Output for Sample Input

    6

    101 101

    0 67

    -101 101

    7678123668327637674887634 101

    11010000000000000000 256

    -202202202202000202202202 -101

    Case 1: divisible

    Case 2: divisible

    Case 3: divisible

    Case 4: not divisible

    Case 5: divisible

    Case 6: divisible

    题解:

    单纯的大数求模。从高位处理到低位。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <cmath>
     7 #include <queue>
     8 #include <stack>
     9 #include <map>
    10 #include <string>
    11 #include <set>
    12 using namespace std;
    13 typedef long long LL;
    14 const int INF = 2e9;
    15 const LL LNF = 9e18;
    16 const int mod = 1e9+7;
    17 const int MAXM = 1e5+10;
    18 const int MAXN = 5e5+10;
    19 
    20 char a[220];
    21 int b;
    22 
    23 int main()
    24 {
    25     int T, kase = 0;
    26     scanf("%d", &T);
    27     while(T--)
    28     {
    29         scanf("%s%d", a, &b);
    30         int len = strlen(a);
    31         b = abs(b);
    32         LL s = 0;
    33         for(int i = (a[0]=='-'); i<len; i++)
    34         {
    35             s *= 10, s += a[i] - '0';
    36             s %= b;
    37         }
    38         printf("Case %d: %s
    ", ++kase, s?"not divisible":"divisible");
    39     }
    40 }
    View Code
  • 相关阅读:
    关于登录或授权页面的错误提示
    弱网环境模拟工具
    Android Fragment 深度解析
    排序算法(七)
    排序算法(六)
    排序算法(五)
    java之数组
    排序算法(四)
    排序算法(三)
    排序算法(二)
  • 原文地址:https://www.cnblogs.com/DOLFAMINGO/p/8371075.html
Copyright © 2011-2022 走看看