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 ...
随机推荐
- 22-关键字:super
1.super 关键字可以理解为:父类的 2.可以用来调用的结构: 属性.方法.构造器 3.super调用属性.方法: 3.1 我们可以在子类的方法或构造器中.通过使用"super.属性&q ...
- python基础语法和实战练习
(一)Python基础学习 Num01:python的基本数据类型 ①字符串:可进行拼接和截取 ②数字:int,float,complex(复数) 涉及到格式转换:int(x)转换为整数,float( ...
- java验证输入是否为三阶幻方
问题描述: 小明最近在教邻居家的小朋友小学奥数,而最近正好讲述到了三阶幻方这个部分,三阶幻方指的是将1~9不重复的填入一个3*3的矩阵当中,使得每一行.每一列和每一条对角线的和都是相同的. 三阶幻方又 ...
- Ubuntu用户都应该了解的快捷键
无论我们使用什么操作系统还是什么软件,快捷键都是非常有用的,因为可以在启动应用程序或跳转到所需窗口,可以快速进行很多操作,而无需动鼠标到处点,节省时间和精力,提高效率. 就像在Windows中一样,U ...
- 【java】解决java compiler level does not match the version of the installed java project facet
翻译内容:java编译器jdk版本与安装的java项目方面的版本不匹配 修改编译器jdk版本 项目右键选择->properties 如果项目的开发版本为,jdk1.8 ,选择修改为1.8 ,点击 ...
- DB2 分组查询语句ROW_NUMBER() OVER() (转载)
说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...
- node.js 出现server instance pool was destroyed
初步判断为MongodbClient断开连接的原因. 之所以断开连接,可能是多个操作间隔时间比较久. 解决方法之一,不要调用close方法.
- 【HAOI2015】树上染色 - 树形 DP
题目描述 有一棵点数为 N 的树,树边有边权.给你一个在 0~ N 之内的正整数 K ,你要在这棵树中选择 K个点,将其染成黑色,并将其他 的N-K个点染成白色 . 将所有点染色后,你会获得黑点两两之 ...
- Linux命令--vi/vim复制一行,粘贴
在光标的位置按“yy”,复制当前行: 然后再光标的行按“p”,粘贴到下一行,原来的往下顺移
- javaString详解
String基础 Java String 类 字符串广泛应用 在 Java 编程中,在 Java 中字符串属于对象,Java 提供了 String 类来创建和操作字符串. 创建字符串 创建字符串最简单 ...