lightoj 1214
lightoj 1214 Large Division (大数除法)
链接:http://www.lightoj.com/volume_showproblem.php?problem=1214
题意:给定 a, b 两个数,判断 a 是否整除 b 。(a 为 大数)
思路: 用字符串存 a ,转化为 整型数组,用除法原理进行处理,没什么难度。其中关键是负号的处理。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; typedef long long LL;
LL b, x, y;
char ar[]; // a
int nu[]; //把 a 字符转化为数字 bool option()
{
int i = , j;
int len = strlen(ar); //a 的长度
if(ar[] == '-') len--, i = ; //去掉 a 的‘-’号
for(j = ; ar[i]; ++j, ++i) //转化
nu[j] = ar[i] - '';
if(b < ) b = -b; //去掉 b 的负号
for(j = , y = ; j < len; ) //循环除法
{
x = y;
while(x <= b && j < len)
{
x = x * + nu[j];
j++;
}
y = x % b;
}
if(y) return false;
return true;
} int main()
{
int t, i = ;
//freopen("in.txt", "r", stdin);
cin >> t;
while(t--)
{
scanf("%s%lld", ar, &b);
printf("Case %d: ", i++);
puts(option() ? "divisible" : "not divisible" );
}
return ;
}
刚才又写了一遍,用的java,刚学java,求不喷:
import java.math.BigInteger;
import java.util.Scanner; /**
* @author Administrator
*
*/
public class Main { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BigInteger a, b;
int t;
Scanner cin = new Scanner(System.in);
t = cin.nextInt();
for(int i = ; i <= t; i++){
a = cin.nextBigInteger();
b = cin.nextBigInteger();
if(a.abs().mod(b.abs()).compareTo(BigInteger.ZERO) == ){
System.out.println("Case "+i+": divisible");
}
else {
System.out.println("Case "+i+": not divisible");
}
}
} }
lightoj 1214的更多相关文章
- LightOJ 1214 Large Division 水题
java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...
- LightOJ 1214 Large Division
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- [kuangbin带你飞]专题十四 数论基础
ID Origin Title 111 / 423 Problem A LightOJ 1370 Bi-shoe and Phi-shoe 21 / 74 Problem B ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- kuangbin 带你飞 数学基础
模版整理: 晒素数 void init() { cas = ; ; i < MAXD ; i++) is_prime[i] = true; is_prime[] = is_prime[] = f ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
- 1214 - Large Division -- LightOj(大数取余)
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
随机推荐
- Caching Data in the Architecture (C#)
http://www.asp.net/web-forms/tutorials/data-access/caching-data/caching-data-in-the-architecture-cs ...
- cenos环境变量配置
Beego环境搭建和bee工具安装使用,以Windows环境为例. 首先,下载并安装好GO并配置好GOROOT和GOPATH环境变量(如果您是用msi包安装的go,那么这些环境变量已经设置好了).并在 ...
- [leetcode-783-Minimum Distance Between BST Nodes]
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- 软工2017第六周团队协作——个人PSP
10.20 --10.26本周例行报告 1.PSP(personal software process )个人软件过程. 类型 任务 开始时间 结束时间 中断时间 实际用 ...
- 软件工程 part4 评价3作品
作品1 抢答器 地址: https://modao.cc/app/ylGTXobcMU7ePNi6tY53gG4iraLl0md评价: 挺好玩,但是字体大小是个缺陷,简单大方. 作品2:连连看 软件工 ...
- HttpServletRequest和HttpServletResponse实例
先看一下web.xml文件配置: <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...
- Java中终止正在运行线程
问题:java 中如何让一个正在运行的线程终止掉? Demo_1: class TT implements Runnable { private boolean flag = true; @Overr ...
- hashMap原理(java8)
(1) HashMap:它根据键的hashCode值存储数据,大多数情况下可以直接定位到它的值,因而具有很快的访问速度,但遍历顺序却是不确定的. HashMap最多只允许一条记录的键为null,允许多 ...
- 大型网站架构演化(六)——使用反向代理和CDN加速网站响应
随着网站业务不断发展,用户规模越来越大,由于中国复杂的网络环境,不同地区的用户访问网站时,速度差别也极大.有研究表明,网站访问延迟和用户流失率正相关,网站访问越慢,用户越容易失去耐心而离开.为了提供更 ...
- lol人物模型提取(八)
今天顺风终于把包裹送到了北航新主楼自提柜,怀着激动喜悦的心情,我小心翼翼地将其取回. 到了晚上,是时候解开佐伊的封印了! 开了个小口,发现里面包得还挺严实的. 去掉了纸盒,里面还有一层 ...