LightOJ - 1214 Large Division 大数取余

import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Scanner;
//import java.text.*;

public class Main {
	public static void main(String[] args) {
        Scanner cin = new Scanner (new BufferedInputStream(System.in));
		//Scanner sc=new Scanner(System.in);
		int T;
        BigInteger a, b, res;
		T = cin.nextInt();
		BigInteger zero = BigInteger.valueOf(0);
        for(int Case = 1; Case <= T; ++ Case){
            a = cin.nextBigInteger();
            b = cin.nextBigInteger();
            if(b.compareTo(zero) < 0){
                b = zero.subtract(b);
            }
            if(a.compareTo(zero) < 0){
                a = zero.subtract(a);
            }
            res = a.mod(b);
            if(res.compareTo(zero) == 0){
                System.out.println("Case " + Case + ": divisible");
            }
            else System.out.println("Case " + Case + ": not divisible");
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; ++ i)
#define per(i, a, n) for(int i = n; i >= a; -- i)
typedef long long ll;
const int N = 5e5 + 105;
const int mod = 998244353;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b) res = (res * a) % mod; a = (a * a) % mod; b >>= 1;} return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
//


int T;
string a;
ll b, carry;

int main()
{
    scanf("%d",&T);
    string::iterator top;
    rep(Case,1,T){
        cin>>a>>b;
        top = a.begin();
        carry  = 0;
        if(a[0] == '-') top ++;
        for(; top != a.end(); top ++){
            carry = carry * 10 + *top - '0';
            carry %= b;
        }
        if(carry) printf("Case %d: not divisible\n",Case);
        else printf("Case %d: divisible\n",Case);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/A-sc/p/12820260.html
今日推荐