LightOJ - 1214-Large Division(c++取模 + java的两种写法)
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
6
101 101
0 67
-101 101
7678123668327637674887634 101
11010000000000000000 256
-202202202202000202202202 -101
Sample Output
Case 1: divisible
Case 2: divisible
Case 3: divisible
Case 4: not divisible
Case 5: divisible
Case 6: divisible
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
typedef long long ll;
using namespace std;
char str[];
int main()
{
int T;
cin>>T;
int b;
int cnt=;
while(T--)
{
scanf("%s",str);
scanf("%d",&b);
if(b<)
b=-b;
int len=strlen(str);
ll ans=;
for(int t=;t<len;t++)
{
if(str[t]>=''&&str[t]<='')
{
ans=((ans*)+(str[t]-''))%b;
}
else
{
continue;
}
}
printf("Case %d: ",cnt++);
if(ans==)
{
puts("divisible");
}
else
{
puts("not divisible");
}
}
return ;
}
import java.math.BigInteger;
import java.util.Scanner; public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int T;
int cnt=1;
T=sc.nextInt();
while(T>=0)
{
BigInteger a,b,c;
a=sc.nextBigInteger();
b=sc.nextBigInteger();
a=a.abs();
b=b.abs(); System.out.print("Case "+cnt+":");
if(a.remainder(b).equals(BigInteger.ZERO))
{
System.out.println(" divisible");
}
else
{
System.out.println(" not divisible");
}
T--;
cnt++;
} } }
import java.math.BigInteger;
import java.util.Scanner; public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int T;
int cnt=1;
T=sc.nextInt();
while(T>=0)
{
BigInteger a,b,c; a=sc.nextBigInteger();
b=sc.nextBigInteger();
a=a.abs();
b=b.abs();
System.out.print("Case "+cnt+":"); if(a.gcd(b).equals(b))
{
System.out.println(" divisible");
}
else
{
System.out.println(" not divisible");
}
T--;
cnt++;
} } }
LightOJ - 1214-Large Division(c++取模 + java的两种写法)的更多相关文章
- LightOJ 1214 Large Division
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- LightOJ 1214 Large Division 水题
java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...
- java路径两种写法"/"和"\\"
String path="D:\\新建文件夹\\2.png"; File file=new File(path); System.out.println(file.exists() ...
- LightOJ1214 Large Division —— 大数求模
题目链接:https://vjudge.net/problem/LightOJ-1214 1214 - Large Division PDF (English) Statistics Forum ...
- light oj 1214 - Large Division
1214 - Large Division PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB G ...
- 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 ...
- java中两种类型变量
Java中有两种类型的变量,一种是对象类型,另一种是基础类型(primitive type). 对象类型普遍采用引用的方式,比如 List a = new ArrayList(); List b = ...
- JAVA 中两种判断输入的是否是数字的方法__正则化_
JAVA 中两种判断输入的是否是数字的方法 package t0806; import java.io.*; import java.util.regex.*; public class zhengz ...
- Java中两种实现多线程方式的对比分析
本文转载自:http://www.linuxidc.com/Linux/2013-12/93690.htm#0-tsina-1-14812-397232819ff9a47a7b7e80a40613cf ...
随机推荐
- CI4框架应用六 - 控制器应用
这节我们来分析一下控制器的应用,我们看到系统提供的控制器都是继承自一个BaseController,我们来分析一下这个BaseController的作用 use CodeIgniter\Control ...
- 03-java实现循环链表
03java实现循环链表 本人git https://github.com/bigeyes-debug/Algorithm 一丶单向循环链表 就是为尾节点指向头结点 二丶单向循环链表的接口设计 比较单 ...
- layui 事件监听触发
1:监听select 改变 <!-- 不用form 用div也可以 --> <form class="layui-form"> <div class= ...
- C#LeetCode刷题之#39-组合总和(Combination Sum)
目录 问题 示例 分析 问题 该文章已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3663 访问. 给定一个无重复元素的数组 candi ...
- C#LeetCode刷题之#876-链表的中间结点(Middle of the Linked List)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3836 访问. 给定一个带有头结点 head 的非空单链表,返回链 ...
- 利用Unity3D制作简易2D计算器
利用Unity3D制作简易2D计算器 标签(空格分隔): uiniy3D 1. 操作流程 在unity3DD中创建一个新项目 注意选择是2D的(因为默认3D) 在Assets框右键新建C#脚本 在新建 ...
- Vulnhub篇Photographerr
0x00 靶机信息 靶机:Photographerr:1 难度:中 下载:https://www.vulnhub.com/entry/photographer-1,519/ 0x01 信息收集 靶场网 ...
- (转)软件产品化,国内IT人之痛
原文链接:http://blog.csdn.net/harrymeng/article/details/5254415 记得在网上看过一则印度软件的有趣故事,意思是先从印度6个不同城市的软件公司中选出 ...
- 前端进阶必读:《JavaScript核心技术开发解密》核心提炼二
前言 最近读勒基本关于前端的数据<JavaScript核心技术开发解密>,<webpack从入门到进阶>...这几本书帮助到我更好的理解JS.webpack在前端技术领域中的作 ...
- MySQL是如何实现事务的ACID
前言 最近在面试,有被问到,MySQL的InnoDB引擎是如何实现事务的,又或者说是如何实现ACID这几个特性的,当时没有答好,所以自己总结出来,记录一下. 事务的四大特性ACID 事务的四大特性AC ...