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 ...
随机推荐
- Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependen
Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependen ...
- 正确认识springcloud的作用。分布式从了解架构到springcloud支撑
转载于 https://www.cnblogs.com/williamjie/p/9369681.html 基于springCloud的分布式架构体系 Spring Cloud作为一套微服务治理的 ...
- C#LeetCode刷题之#389-找不同(Find the Difference)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4062 访问. 给定两个字符串 s 和 t,它们只包含小写字母. ...
- 《闲扯Redis十》Redis 跳跃表的结构实现
一.前言 Redis 提供了5种数据类型:String(字符串).Hash(哈希).List(列表).Set(集合).Zset(有序集合),理解每种数据类型的特点对于redis的开发和运维非常重要. ...
- BLE MESH 学习[1] - ESP32 篇
BLE MESH 学习 BLE MESH 是一种蓝牙(n:m)组网的技术. 本篇先介绍 BLE MESH 到使用 ESP32 的官方示例对其进行学习讲解. 后面会进一步学习 SIG 的 BLE MES ...
- 神经网络实现fashion数据集
import tensorflow as tf import numpy as np fashion=tf.keras.datasets.fashion_mnist (x_train,y_train) ...
- Python 函数为什么会默认返回 None?
Python 有一项默认的做法,很多编程语言都没有--它的所有函数都会有一个返回值,不管你有没有写 return 语句. 本文出自"Python为什么"系列,在正式开始之前,我们就 ...
- three.js 利用uv和ThreeBSP制作一个快递柜
最近有three网友,问我要不要学习blender,其实我感觉学习一下也无妨,不过花大量时间精通,尚可不必,术业有专攻给别人留一条路吧,哈哈.那我我们就是用ThreeBSP和uv贴图的知识来制作一个定 ...
- 如何校验内存数据的一致性,DynamicExpresso 算是帮上大忙了
一:背景 1. 讲故事 记的在上一家公司做全内存项目的时候,因为一些关键表会在程序 startup 的时候全量灌入到内存中,但随着时间的推移,内存和数据库的同步偶尔会出现数据差异的情况,伴随着就是运营 ...
- exe调用DLL的方式
假设被调用的DLL存在一个导出函数,原型如下: void printN(int); 三种方式从DLL导入导出函数 生成DLL时使用模块定义 (.def) 文件 在主应用程序的函数定义中使用关键字__d ...