AtCoder Beginner Contest 142【D题】【判断素数的模板+求一个数的因子的模板】
D - Disjoint Set of Common Divisors
Problem Statement
Given are positive integers AA and BB.
Let us choose some number of positive common divisors of AA and BB.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisorDefinition of being coprimeDefinition of dividing
Constraints
- All values in input are integers.
- 1≤A,B≤10121≤A,B≤1012
Input
Input is given from Standard Input in the following format:
- AA BB
Output
Print the maximum number of divisors that can be chosen to satisfy the condition.
Sample Input 1 Copy
- 12 18
Sample Output 1 Copy
- 3
1212 and 1818 have the following positive common divisors: 11, 22, 33, and 66.
11 and 22 are coprime, 22 and 33 are coprime, and 33 and 11 are coprime, so we can choose 11, 22, and 33, which achieve the maximum result.
Sample Input 2 Copy
- 420 660
Sample Output 2 Copy
- 4
Sample Input 3 Copy
- 1 2019
Sample Output 3 Copy
- 1
11 and 20192019 have no positive common divisors other than 1
思路:找出有多少个公因子,并且公因子必须是素数。然后再加一。【比赛时思路一模一样,代码写挫了QAQ】
AC代码:
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- bool isprime(int num){ // 判断是否是素数
- if(num==){
- return false;
- }
- if(num==)
- return true;
- if(num%==)
- return false;
- double sqrtNum = sqrt(num);
- for (int i = ; i <= sqrtNum; i += )
- {
- if (num % i == )
- {
- return false;
- }
- }
- return true;
- }
- vector<int> v;
- signed main(){
- int n,m;
- cin>>n>>m;
- int temp=min(n,m);
- for(int i=;i*i<=temp;i++){ // 求一个数的因子的模板
- if(temp%i==){
- v.push_back(i);
- if(i*i!=temp){
- v.push_back(temp/i);
- }
- }
- }
- int ans=;
- int t=max(n,m);
- for(int i=;i<v.size();i++){
- if(t%v[i]==&&isprime(v[i]))
- ans++;
- }
- cout<<ans+;
- return ;
- }
AtCoder Beginner Contest 142【D题】【判断素数的模板+求一个数的因子的模板】的更多相关文章
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
- AtCoder Beginner Contest 069 ABCD题
题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...
- AtCoder Beginner Contest 070 ABCD题
题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 057 ABCD题
A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...
- AtCoder Beginner Contest 215 F题题解
F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...
- AtCoder Beginner Contest 051 ABCD题
A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...
- AtCoder Beginner Contest 137 D题【贪心】
[题意]一共有N个任务和M天,一个人一天只能做一个任务,做完任务之后可以在这一天之后的(Ai-1)天拿到Bi的工资,问M天内最多可以拿到多少工资. 链接:https://atcoder.jp/cont ...
随机推荐
- java 中的容器(札记)
创建容器向上转型为接口的时候,有时候,并不是一定可行的,因为有的实现类,在接口的基础添加了自己的方法:比如:List 接口下面的 LinkedList 自己定义了一些方法 : Arrays.asLis ...
- 【C++札记】引用
介绍 引用是C++中特有的语法,在C语言中不存在. 本质上引用(reference)就是指针,在类型名后面加上一个&号就是引用类型. 1.指针与引用的定义进行比较 指针定义: 引用定义: in ...
- PAT(B) 1013 数素数(Java)
题目链接:1013 数素数 代码 /** * Score: 20 * Run Time: 124ms * @author wowpH * @version 1.0 */ import java.uti ...
- 初始STM32
主要内容: 1.什么是STM32 STM32有什么 STM32怎么选型号 一:什么是STM32 ST— 意法半寻体,是一个公司名,即SOC厂商(ARM是IP厂商,STM32中内核由ARM设计,外设例如 ...
- g++ 生成C++ .so库文件,并调用示例
Tags: g++ C++ so library 在Linux系统下用g++命令编译C++程序.也可以生成so,a链接库 示例一 编译时链接so库 Test.h 文件内容 Main.cpp ...
- 如何在 vue 2.0+ 中引入全局的stylus文件,且能正常
由于stylus在引用时,不能像一般的css文件直接在main.js中引用,就算引用了也会只能使用转换后的css,不能使用里面的函数,方法等,原因可能是:在这里引入会被直接编译成css,不能在别的模板 ...
- Hibernate-validate工具类,手动调用校验返回结果
引言:在常见的工程中,一般是在Controller中校验入参,校验入参的方式有多种,这里介绍的使用hibernate-validate来验证,其中分为手动和自动校验,自动校验可以联合spring,使用 ...
- iOS有哪些数据类型/基本数据类型?
简述 本文主要探究使用OC作为iOS开发语言时,我们能使用哪些数据类型. 一切类型始于C. C语言的类型 基本数据类型: 基本数据类型(fundamental data types)也叫原始数据类型( ...
- 1.NIO概述
/*Java NIO 简介*/ java NIO (New IO)是从 java1.4版本开始引入的一个新的IO API,可以替代标准的 java IO API (jdk1.7又对其进行了改进, 称为 ...
- Sharing is only supported for boot loader classes because bootstrap classpath has been appended
在idea里面运行项目,terminal里面报“Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boo ...