CF1245 A. Good ol' Numbers Coloring(java与gcd)
题意:给定数字A和数字B,问是否满足gcd(A,B)==1。
思路:可以直接写函数gcd。也可以用大数自带的gcd功能。
代码1:
/*
@author nimphy
@create 2019-11-06-12:07
about:
*/
import java.io.*;
import java.util.*;
public class CF1245 {
public static void main(String[] args) {
Scanner In=new Scanner(System.in);
int T,A,B,C;
T=In.nextInt();
){
A=In.nextInt();
B=In.nextInt();
C=gcd(A,B);
) System.out.println("Finite");
else System.out.println("Infinite");
}
}
static int gcd(int x,int y)
{
int t;
){
t=x%y;
x=y;
y=t;
}
return x;
}
}
代码2:大数 ~ java有自带进制转化功能,可以参考hdu5050;
/*
@author nimphy
@create 2019-11-06-12:07
about:
*/
import java.math.*;
import java.io.*;
import java.util.*;
public class CF1245 {
public static void main(String[] args) {
Scanner In = new Scanner(System.in);
int T;
T = In.nextInt();
) {
String s1, s2;
s1 = In.next();
s2 = In.next();
BigInteger A = new BigInteger(s1);//将转换成十进制的数转换成大数
BigInteger B = new BigInteger(s2);
BigInteger C = A.gcd(B);
if (C.equals(BigInteger.ONE)) System.out.println("Finite");
else System.out.println("Infinite");
}
}
}
CF1245 A. Good ol' Numbers Coloring(java与gcd)的更多相关文章
- Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring
链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- Add Two Numbers LeetCode Java
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- LeetCode201 Bitwise AND of Numbers Range Java 题解
题目: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all num ...
- LeetCode算法题-Self Dividing Numbers(Java实现)
这是悦乐书的第305次更新,第324篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第173题(顺位题号是728).自分割数是一个可被其包含的每个数字整除的数字.例如,12 ...
- LeetCode算法题-Sum of Square Numbers(Java实现)
这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的 ...
- LeetCode算法题-Maximum Product of Three Numbers(Java实现)
这是悦乐书的第275次更新,第291篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第143题(顺位题号是628).给定一个整数数组,从其中找出三个数,使得乘积最大.例如: ...
- LeetCode Two Add Two Numbers (JAVA)
问题简介:输入两个数字链表,输出求和后的链表(链表由数字位数倒序组成) 问题详解: 给定两个非空链表,表示两个非负整数. 数字以相反的顺序存储,每个节点包含一位数字.对两个整数作求和运算,将结果倒序作 ...
- ZOJ 3987 Numbers(Java枚举)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3987 题意:给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n ...
随机推荐
- 牛客小白月赛18 Forsaken喜欢数论
牛客小白月赛18 Forsaken喜欢数论 题目传送门直接点标题 Forsaken有一个有趣的数论函数.对于任意一个数xxx,f(x)f(x)f(x)会返回xxx的最小质因子.如果这个数没有最小质 ...
- JAVA的addAll方法
List和collections工具类都有这个方法!
- 【ECNU620】数学题(结论题)
点此看题面 大致题意: 求\((n-1)!\ mod\ n\)的值. 大力猜结论 首先,看到样例,我们可以猜测: 当\(n\)为质数时,答案为\(n-1\). 当\(n\)为合数时,答案为\(0\). ...
- Paper | Learning convolutional networks for content-weighted image compression
目录 摘要 故事要点 模型训练 发表在2018年CVPR. 以下对于一些专业术语的翻译可能有些问题. 摘要 有损压缩是一个优化问题,其优化目标是率失真,优化对象是编码器.量化器和解码器(同时优化). ...
- CSP-J&S2019前颓废记
说了是颓废记,就是颓废记,因为真的很颓废...... 2018年12月 我看懂了<啊哈算法>(仅仅是看懂,并没有完全学会,只看得懂,却不会敲) 插曲:八上期末考试 我们老师阻挠我继续学OI ...
- jquery模拟点击事件
在某些情况下,我们需要自动执行一些点击事件.比如:一些 tab 一般是通过点击事件来加载不同的数据内容. 而如果要页面加载完直接显示第三个 tab,怎么办呢?此时就需要用到 jQuery 的模拟点击事 ...
- JWT签名与验签
签名Token生产 using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; usi ...
- 探索 ASP.Net Core 3.0系列五:引入IHostLifetime并弄清Generic Host启动交互
前言:在本文中,我将介绍如何在通用主机之上重新构建ASP.NET Core 3.0,以及由此带来的一些好处. 同时也展示了3.0中引入新的抽象类IHostLifetime,并描述了它在管理应用程序(尤 ...
- 在net Core3.1上基于winform实现依赖注入实例
目录 在net Core3.1上基于winform实现依赖注入实例 1.背景 2.依赖注入 2.1依赖注入是什么? 2.1依赖注入的目的 2.2依赖注入带来的好处 2.2.1生命周期的控制 2.2.2 ...
- 九、Spring之BeanFactory源码分析(一)
Spring之BeanFactory源码分析(一) 注意:该随笔内容完全引自https://blog.csdn.net/u014634338/article/details/82865644,写的 ...