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 ...
随机推荐
- luogu P1140 相似基因
题目背景 大家都知道,基因可以看作一个碱基对序列.它包含了4种核苷酸,简记作A,C,G,T.生物学家正致力于寻找人类基因的功能,以利用于诊断疾病和发明药物. 在一个人类基因工作组的任务中,生物学家研究 ...
- Loj #125. 除数函数求和(2)
link : https://loj.ac/problem/125 分块calc即可. #include<bits/stdc++.h> #define ll long long using ...
- Linux下Shell的快捷键(转)
下述所有命令在Linux/Unix的shell下有效,这里以bash为主.如有出入,以你自己的服务器为准.本文所指的Linux主要指RHEL/CentOS,Unix指的是FreeBSD,这也是Unix ...
- 转: MySQL索引原理及慢查询优化 (from 美团技术博客)
转: http://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色, ...
- Seinfeld(杭电3351)
Seinfeld Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- TNS-01201: Listener cannot find executablen 错误
近期在启动监听器的时候收到了TNS-01201: Listener cannot find executable...的错误提示.这个错误还真是一个一直没有碰到过的错误.咋一看还真不明确是怎么一回事呢 ...
- hadoop集群ambari搭建(2)之制作hadoop本地源
准备好源资源server,我使用之前的一台node4,配置都是1GB内存20GB存储 集群最好的安装方式一定是通过本地源的,假设是公共源,那么网络将会严重影响我们的安装进度.所以制作本地源是每个大数据 ...
- Linux的基本使用
检测某个地址是否可以通信:ping xx.xx.xx.xx 检测某个端口是否开启:telnet xx.xx.xx.xx port 端口:用来区别不同服务 常用命令: 创建一个目录 /data mkdi ...
- cocos2dx3.2 学习笔记(2)--ActionManagerTest
前面看完了 CppTests的基本框架及流程.如今准备看看详细的每一个Test了 从哪里開始看呢. 额,就第一个吧(ActionManagerTest) 首先看看效果吧,执行了下.发现有几种效果.看不 ...
- jQuery UI Autocomplete是jQuery UI的自动完成组件
支持的数据源 jQuery UI Autocomplete主要支持字符串Array.JSON两种数据格式. 普通的Array格式没有什么特殊的,如下: ? 1 ["cnblogs" ...