LightOJ 1214(大数相除)

Large Division

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

6

101 101

0 67

-101 101

7678123668327637674887634 101

11010000000000000000 256

-202202202202000202202202 -101

Sample Output

Case 1: divisible

Case 2: divisible

Case 3: divisible

Case 4: not divisible

Case 5: divisible

Case 6: divisible

直接上Java

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		BigInteger a, b;
		int t;
		t = in.nextInt();
		for (int i = 1; i <= t; i++) {
			a = in.nextBigInteger();
			b = in.nextBigInteger();
			if(b.compareTo(BigInteger.ZERO)<0) b=b.multiply(BigInteger.valueOf(-1));
			BigInteger c = a.mod(b);
			if (c == BigInteger.ZERO)
				System.out.println("Case " + i + ": " + "divisible");
			else
				System.out.println("Case " + i + ": " + "not divisible");
		}
	}

}
时间: 2024-10-13 20:05:14

LightOJ 1214(大数相除)的相关文章

大数模拟——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 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1214 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 d

华为机试—大数相减

题目:大数相减 输入两行字符串正整数,第一行是被减数,第二行是减数,输出第一行减去第二行的结果. 备注:1.两个整数都是正整数,被减数大于减数 示例: 输入:1000000000000001       1 输出:1000000000000000 #include <stdio.h> #include <string.h> #define MAX 100 //100位大数相减 int bigNumSub(char a[],char b[],char sub[]) { int i=0

YT15-HDU-How many fibs(大数相加法)

Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n >= 3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a, b]. Input The input contains several test cases. Each

[算法]大数相减

今天在小米OJ上看到一道题(https://code.mi.com/problem/list/view?id=3), 很有意思, 试着做了一下 描述: 两个长度超出常规整形变量上限的大数相减,请避免使用各语言内置大数处理库,如 Java.math.BigInteger 等. 输入: 有 N 行测试数据,每一行有两个代表整数的字符串 a 和 b,长度超过百位.规定 a>=b,a, b > 0. 测试结果可以用 linux 小工具 bc进行测试是否正确. 输出: 返回表示结果整数的字符串. 输入样

每日一练:#002大数相减

描述 两个长度超出常规整形变量上限的大数相减,请避免使用各语言内置大数处理库,如 Java.math.BigInteger 等. 输入 有 N 行测试数据,每一行有两个代表整数的字符串 a 和 b,长度超过百位.规定 a>=b,a, b > 0. 测试结果可以用 linux 小工具 bc进行测试是否正确. 输出 返回表示结果整数的字符串. 输入样例 1231231237812739878951331231231237812739878951331231231237812739878951331

L1-046 整除光棍 [大数相除]

写都写了,当大数相除模版吧 #include<iostream> #include<cstdio> #include<string.h> #include<string> #include<math.h> #include<map> #define maxn 10005 using namespace std; typedef long long ll; int n,p; string s; int ans[maxn]; bool j

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的同商. 对于同余有三种

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