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 ...
随机推荐
- 有用的20个Python代码段
Python是一种非BS编程语言.设计简单和易读性是它广受欢迎的两大原因.正如Python的宗旨:美丽胜于丑陋,显式胜于隐式. 记住一些帮助提高编码设计的常用小诀窍是有用的.在必要时刻,这些小诀窍能够 ...
- 【工具】之001-CentOS7 最小化安装配置
写在前面 我很懒,,,不想敲一个命令一个命令敲... "偷懒是有前提的,不是之前,就是之后." 简述 CentOS 7 最小化安装版本:CentOS-7-x86_64-Minima ...
- 学习Hibernate5 JPA这一篇就够了
配套资料,免费下载 链接:https://pan.baidu.com/s/158JkczSacADez-fEMDXSYQ 提取码:2ce1 复制这段内容后打开百度网盘手机App,操作更方便哦 第一章 ...
- JVM初探(三):类加载机制
一.概述 我们知道java代码会被编译为.class文件,这里class文件中的类信息最终还是需要jvm加载以后才能使用. 事实上,虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验,转 ...
- Vue Slots
子组件vue <template> <div> <slot v-if="slots.header" name="header"&g ...
- 如何为你的IDEA安装插件——几个实用插件推荐
文章目录 如何为你的IDEA安装插件--几个实用插件推荐 安装插件 插件推荐 1.Background Image Plus 2.Translation 3.CodeGlance 4.Rainbow ...
- SpringBoot ---yml 整合 Druid(1.1.23) 数据源
SpringBoot ---yml 整合 Druid(1.1.23) 数据源 搜了一下,网络上有在配置类写 @Bean 配置的,也有 yml 配置的. 笔者尝试过用配置类配置 @Bean 的方法,结果 ...
- Oracle 多条数据转一行逗号隔开
wm_concat 例: select wm_concat(市) from pa50 where apa132=省
- git pull冲突的解决方案
处理步骤: 1.先将本地修改存储起来 $ git stash 这样本地的所有修改就都被暂时存储起来 .使用git stash list可以看到保存的信息: git stash暂存修改 其中stash@ ...
- 使用IDEA连接mysql后不显示表的解决方案
使用idea连接mysql后显示如下: 没有显示我们要看的数据表.?????????? 解决方法: 点设置: 选择要看的数据库名称,保存后就OK了.