LightOJ 1214 Large Division(大整数取模)
来源:互联网 发布:比较好的php框架 编辑:程序博客网 时间:2024/05/21 10:48
题目链接:
LightOJ 1214 Large Division
题意:
大整数取模。输入a,b(-10^200 <= a <= 10^200, b != 0, b是int),判断a能否整除b。
分析:
把大整数写成“从左向右”的形式:如:1234 = ((1 * 10 + 2) * 10 + 3) * 10 + 4.然后根据(n + m) % p = ((n % p) + (m % p)) % p,每步去模。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <climits>#include <cmath>#include <ctime>#include <cassert>#define IOS ios_base::sync_with_stdio(0); cin.tie(0);using namespace std;typedef long long ll;const int MAX_N = 250;int T, cases = 0, p;char s[MAX_N];int main(){ scanf("%d", &T); while(T--){ scanf("%s%d", &s, &p); printf("Case %d: ", ++cases); int len = strlen(s); if(s[0] == '0' && len == 1){ printf("divisible\n"); continue; } if(p < 0) p = -p; int ans = 0, st = 0; if(s[0] == '-') st = 1; for(int i = st; i < len; i++){ ans = (int)(((ll) ans * 10 + s[i] - '0') % p); } if(ans == 0) printf("divisible\n"); else printf("not divisible\n"); } return 0;}
0 0
- LightOJ 1214 Large Division(大整数取模)
- Large Division(大整数取模)
- LightOJ 1214 - Large Division (大数取余)
- LightOJ Large Devision (大整数取模)
- LightOJ 1214 Large Division
- lightOJ 1214 Large Division
- LightOJ 1214 Large Division
- LightOJ 1214Large 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][Java] Large Division
- LightOJ 1214 - Large Division (同余定理)
- 【技巧-模拟除法】LightOJ Large Division 1214
- LightOJ 1214 - Large Division【同余定理】
- 一道关于重载的例子
- LeetCode:Distinct Subsequences
- Android开发技术点
- 利用广播接受者监听用户短信
- C++基础<01>—C++初识
- LightOJ 1214 Large Division(大整数取模)
- 利用js+php的技术,实现全国地址多级联动的功能
- 图片的翻转_opencv
- 从源码学Android(一) : Android源码编译
- JS报错:Uncaught SyntaxError: Unexpected identifier
- Android项目使用Ant打包,自动生成build.xml
- Boost string_algo
- JavaScript的常用内置类
- CodeForces 3D Least Cost Bracket Sequence (贪心+优先队列)