Large Division
Time Limit: 1000 ms memory limit: 32768kb 64bit Io format: % LLD & % LlU
Submit
Status
Practice
Lightoj 1214
Description
Given two integers, A and B, you shoshould 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 'divisable' if A is divisible by B. Otherwise print 'not divisable '.
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
<Span style = "color: # 6600cc; "> /************************************* * ***** Author: grant yuan time: 2014.8.7 algorithm: large number total division Source: Light OJ 1214 explain: starts from ans initialization to 0, and ANS = (ANS + s [I]-'0 ') % B; finally, if ANS is equal to 0, it can be divisible; otherwise, it cannot be divisible; **************************************** * *****/# include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # define INF 0x3fffffffusing namespace STD; char s [2000002]; int B; long ans; int t; int main () {scanf ("% d", & T); For (INT I = 1; I <= T; I ++) {memset (S, 0, sizeof (s); scanf ("% S % d", & S, & B ); if (B <0) B =-B; int L = strlen (s); ans = 0; For (Int J = 0; j <L; j ++) {If (s [J] = '-') continue; ans = (ANS * 10 + (s [J]-'0') % B ;} if (ANS = 0) printf ("case % d: divisible \ n", I); else printf ("case % d: not divisible \ n", I );} return 0 ;}</span>