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 ...
随机推荐
- make makefile cmake qmake都是什么,有什么区别
原文:https://www.zhihu.com/question/27455963 作者:玟清链接:https://www.zhihu.com/question/27455963/answer/36 ...
- ros pub sub ("~")
base_velocity_smoother.cpp remap ("~") 订阅: "cmd_vel" ...
- UVA - 10972 RevolC FaeLoN
一道特别好的题qwq. 题目大意就是给你一个无向图,让你把边定向之后再加一些边使得这个图强连通,求最少需要加多少边. 一开始毫无头绪23333,数据范围让人摸不着头脑..... 然后开始画图,,,发现 ...
- 【原】手写spring async异步组件
最近在工作中使用到了spring自带的Async,主要是为了把其中耗时多.响应慢.计算复杂的业务抽取几个模块出来,并行查询.不得不说spring自带的比传统线程池提交在代码层次上看起来优雅简洁了不少 ...
- [转] 常用SQL查询语句
sunada 的原文地址 常用SQL查询语句 一.简单查询语句 1. 查看表结构 SQL>DESC emp; 2. 查询所有列 SQL>SELECT * FROM emp; 3. 查询指 ...
- 通过HTML5 FileReader实现上传图片预览功能
原文:http://www.htmleaf.com/ziliaoku/qianduanjiaocheng/201706224590.html 在上传图片到服务器之前,我们希望可以预览一下要上传的图片. ...
- GO语言_用redis作为url队列的爬虫
// Copyright 2016 laosj Author @songtianyi. All Rights Reserved. // // Licensed under the Apache Lic ...
- windows10系统下安装nginx的安装步骤
打开nginx的官网:http://nginx.org/,下载最新的稳定版本. 下载完成后,解压到你想要解压的文件路径中,我解压到了D盘中,并把文件名改为nginx:进入文件内,打开nginx.e ...
- python matplotlib imshow热图坐标替换/映射
今天遇到了这样一个问题,使用matplotlib绘制热图数组中横纵坐标自然是图片的像素排列顺序, 但是这样带来的问题就是画出来的x,y轴中坐标点的数据任然是x,y在数组中的下标, 实际中我们可能期望坐 ...
- 转: 多版本并发控制(MVCC)在分布式系统中的应用 (from coolshell)
from: http://coolshell.cn/articles/6790.html 问题 最近项目中遇到了一个分布式系统的并发控制问题.该问题可以抽象为:某分布式系统由一个数据中心D和若干业务 ...