light oj 1214 - Large Division 大数除法
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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#define N 1000010
using namespace std;
char ar[N];
int nu[N];
long long m;
void option()
{
long long x, y;
int j;
int i = 0;
int len = strlen(ar);
if(ar[0] == '-')
{
len--;
i = 1;///判断是否为负数,i为ar数组的起始下标。
}
for( j = 0; ar[j]; j++, i++)
nu[j] = ar[i] - '0';///将字符串转换为数字。
if(m < 0)
m = -m;
for(j = 0, y = 0; j < len; )
{
x = y;
while(x <= m && j < len)
{
x = x * 10 + nu[j];
j++;
}
y = x % m;
}
if(y)
printf("not divisible\n");
else
printf("divisible\n");
}
int main(void)
{
int T, cas;
scanf("%d", &T);
cas = 0;
while(T--)
{
cas++;
scanf("%s%lld", ar, &m);
printf("Case %d: ", cas);
option();
}
return 0;
}
light oj 1214 - Large Division 大数除法的更多相关文章
- light oj 1214 - Large Division
1214 - Large Division PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB G ...
- LightOJ1214 Large Division —— 大数求模
题目链接:https://vjudge.net/problem/LightOJ-1214 1214 - Large Division PDF (English) Statistics Forum ...
- (大数 求余) 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 ...
- LightOJ 1214 Large Division
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- 1214 - Large Division -- LightOj(大数取余)
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...
- LightOJ 1214 Large Division 水题
java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...
- Light OJ 1214
简单大数模拟题: #include<bits/stdc++.h> using namespace std; typedef long long ll; string Num; vector ...
- 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 ...
- Large Division (大数求余)
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
随机推荐
- 一个命令解决linux重启nginx就丢失pid文件问题
sudo nginx -c /etc/nginx/nginx.conf
- 2018 CCPC 网络赛
The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...
- python __init__()类构造方法
构造方法用于创建对象时使用,每当创建一个类的实例对象时,python解释器都会自动调用它. class Person: def __init__(self): print("调用构造方法&q ...
- Java8 Stream用法详解
1.概述 Stream 的原理:将要处理的元素看做一种流,流在管道中传输,并且可以在管道的节点上处理,包括过滤筛选.去重.排序.聚合等.元素流在管道中经过中间操作的处理,最后由最终操作得到前面处理的结 ...
- Selenium(七):截图显示等待
一.显示等待(有条件等待) 常见问题: 定位明明是对的,为什么运行代码没找到定位. 定位明明是对的,找到定位了,文本信息为什么取到是空的? 分析原因: 没有处理frame 页面渲染速度比自动化测试的代 ...
- 深浅拷贝 集合(定义,方法) 函数(定义,参数,return,作用域) 初识
深浅拷贝 在python中浅拷贝 a=[1,2,3,4,]b=a.copy()b[0]='3333'print(a) #[1, 2, 3, 4] 浅拷贝一层并不会对a造成变化print(b) #[33 ...
- logback 发送邮件和自定义发送邮件;java类发送邮件
使用logback发送邮件 需求: 1.报错发邮件,定位错误位置以尽快解决:(报错发送邮件) 2.某一项重要操作完成之后发送邮件:(自定义发送邮件) 没有接触过logback,怎么办? 没办法,硬着头 ...
- freemark 基本使用
实际上用程序语言编写的程序就是模板. FTL (代表FreeMarker模板语言). 这是为编写模板设计的非常简单的编程语言. 模板(FTL编程)是由如下部分混合而成的: 文本:文本会照着原样来输出. ...
- [GPU高性能编程CUDA实战].(桑德斯).聂雪军等.扫描版-百度云分享
链接:https://pan.baidu.com/s/1NkkDiyRgmfmhm9d2g_GBKQ 提取码:3usj
- Vue使用better-scroll左右菜单联动
说明 最近想做一个vue商城小项目,练习一下vue的语法,刚刚好碰到了需要左右菜单实现联动,因此就接触了 better-scroll. github地址 中文文档. 代码 页面结构以及数据 //页面结 ...