lightoj 1214 - Large Division 【判大数整除 拆分字符串 同余】
来源:互联网 发布:彩票统计软件 编辑:程序博客网 时间:2024/05/29 08:59
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
题意:给你一个a (-10^100 <= a <= 10^100),又给你一个b(int范围),问你b能否整除a。
思路:用字符串表示a,然后依次拆分每一位,根据同余性质对b取余到最后一位,判断最后结果是否为0。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN 500000+10#define MAXM 50000000#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long longusing namespace std;int main(){ int t, kcase = 1; Ri(t); W(t) { LL mod; char str[200]; Rs(str); Rl(mod); int s = 0; int len = strlen(str); if(str[0] == '-') s++; LL ans = 0; if(mod < 0) mod = -mod; for(int i = s; i < len; i++) ans = (ans * 10 + str[i]-'0') % mod; if(ans == 0) printf("Case %d: divisible\n", kcase++); else printf("Case %d: not divisible\n", kcase++); } return 0;}
- lightoj 1214 - Large Division 【判大数整除 拆分字符串 同余】
- LightOJ 1214 - Large Division (同余定理)
- LightOJ 1214 - Large Division【同余定理】
- LightOJ 1214 - Large Division 【同余定理】
- lightoj 1214 - Large Division【同余定理】
- LightOJ 1214 - Large Division (大数取余)
- lightoj--1214--Large Division(大数取余)
- LightOJ 1214 - Large Division (大数求余)
- lightoj 1214 - Large Division 大数对小数取余
- lightoj 1214 - Large Division 大数对小数取余
- LightOJ1214 Large Division (大数求余,同余定理)
- Light oj 1214 Large Division(同余定理,判断是否整除)
- LightOj 1214 Large Division(大数除法)
- 【lightoj 1214】Large Division (大数除法)
- Large Division 同余定理
- light oj 1214 - Large Division (同于定理--整除运算)
- LightOJ 1214 Large Division
- lightOJ 1214 Large Division
- Train Problem I
- 日经春秋 20151104
- **[Hive]用concat_w实现将多行记录合并成一行**
- mac远程桌面连接无法验证您希望连接的计算机的身份
- USB core(三) - hub.c
- lightoj 1214 - Large Division 【判大数整除 拆分字符串 同余】
- Java 8 新特性终极指南
- String str=newString("abc")创建了多少个对象
- hdoj--1824--Let's go home(2-sat)
- java基础之冒泡排序
- Linux下/proc目录简介
- java中常用的字符串的截取方法
- Python 中 import 的机制与实现
- hdoj 1087Super Jumping! Jumping! Jumping!【dp】