LightOJ1214 Large Division —— 大数求模
题目链接:https://vjudge.net/problem/LightOJ-1214
Time Limit: 1 second(s) | Memory Limit: 32 MB |
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 |
题解:
单纯的大数求模。从高位处理到低位。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int MAXM = 1e5+;
const int MAXN = 5e5+; char a[];
int b; int main()
{
int T, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%s%d", a, &b);
int len = strlen(a);
b = abs(b);
LL s = ;
for(int i = (a[]=='-'); i<len; i++)
{
s *= , s += a[i] - '';
s %= b;
}
printf("Case %d: %s\n", ++kase, s?"not divisible":"divisible");
}
}
LightOJ1214 Large Division —— 大数求模的更多相关文章
- Large Division (大数求余)
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- LightOJ1214 Large Division
/* LightOJ1214 Large Division http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1 ...
- 大数求模 sicily 1020
Search
- light oj 1214 - Large Division 大数除法
1214 - Large Division Given two integers, a and b, you should check whether a is divisible by b or n ...
- LightOJ1214 Large Division 基础数论+同余定理
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- L - Large Division (大数, 同余)
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- [18/12/3]蓝桥杯 练习系统 入门级别 Fibonacci数列求模问题 题解思路
前言略. 看到这个题目本来应该很高兴的,因为什么,因为太TM的基础了啊! 可是当你用常规方法尝试提交OJ时你会发现..hhh...运行超时..(开心地摇起了呆毛 //Fibonacci数列递归一般问题 ...
- (大数 求余) Large Division Light OJ 1214
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- (POJ2635)The Embarrassed Cryptographer(大数取模)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...
随机推荐
- SpringCloud 分布式事务解决方案
目录 TX-LCN分布式事务框架 TX-LCN分布式事务框架 随着互联化的蔓延,各种项目都逐渐向分布式服务做转换.如今微服务已经普遍存在,本地事务已经无法满足分布式的要求,由此分布式事务问题诞生. 分 ...
- char 转string
c++: string.c_str() ---------> c: char c; string str;stringstream stream;stream << ...
- 东方14ACM小组 15:Challenge 11
Challenge 11 查看 提交 统计 提问 总时间限制: 10000ms 单个测试点时间限制: 1000ms 内存限制: 262144kB 描述 给一个长为N的数列,有M次操作,每次操作是 ...
- Eclipse安装Spring工具套件
前言: 安装spring工具套件是为了更快捷的使用spring,但是我觉得既然已经有了maven,工具套件其实不那么重要. 而且装好后我发觉没什么两样,只是新建bean文件时比较爽一点. 安装步骤: ...
- cacti监控linux和windows磁盘IO
cacti监控linux和windows磁盘IO 标签:cacti linux磁盘IO windows磁盘IO 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则 ...
- 阿里云云服务器ubuntu配置nginx+uwsgi+django记录文档
1 安装ssh 1 sudo apt-get update 2 sudo apt-get install openssh-server 3 sudo ps -e |grep ssh 有sshd ...
- 转:在CentOS下编译安装GCC
转:https://teddysun.com/432.html 在CentOS下编译安装GCC 技术 秋水逸冰 发布于: 2015-09-02 更新于: 2015-09-02 6519 次围观 ...
- hibernater-validator jar包冲突的问题
在引用hibernater-validator jar包时一直抛出异常,在引用带有该包的项目,或者同时在一个项目中使用该包和validator包都会抛出以下异常 最后发现是在Eclipse环境下,不能 ...
- 使用 rman duplicate from active database 搭建dataguard 手记--系列二
run { allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate channel prmy3 typ ...
- <转>关于 error LNK2019:无法解析的外部符号 ,该符号在函数**中被引用的思考
错误提示信息摘抄如下: ---------------------------------------------------------------------------------------- ...