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 ...
随机推荐
- pandas数据结构之Series笔记
对Series的理解也源于对其相关的代码操作,本次仅贴一些代码来加深理解以及记忆 import pandas as pd import numpy as np s = pd.Series(np.ran ...
- 『Python基础』第2节: Python简介及入门
一. Python介绍 Python是一门高级计算机程序设计语言,1989年,荷兰的Guido von Rossum创造了它.Guido是是一个牛人,1982年,他从阿姆斯特丹大学获得了数学和计算机硕 ...
- java获取端口号,不用request
Integer port = null; MBeanServer mBeanServer = null; List<MBeanServer> mBeanServers = MBeanSer ...
- ggplot2|theme主题设置,详解绘图优化-“精雕细琢”-
本文首发于“生信补给站”公众号,https://mp.weixin.qq.com/s/hMjPj18R1cKBt78w8UfhIw 学习了ggplot2的基本绘图元素ggplot2|详解八大基本绘图要 ...
- poj 2915
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> ...
- (十四)SpringBoot之事务处理
一.简介 ssh ssm都有事务管理service层通过applicationContext.xml配置,所有service方法都加上事务操作: 用来保证一致性,即service方法里的多个dao操作 ...
- Sql Server有主外键关系时添加、删除数据
当表之间有主外键关系时删除数据会被约束,添加.删除失败 解决办法,我们可以先把主外键关系的检查约束给关掉 → 然后删除数据 → 之后再把约束打开 查询出关掉所有外键约束的语句 SELECT 'ALTE ...
- MQTTnet 3.0.5学习笔记
段时间在使用MQTTnet,都说这个东西比较好,可是翻了翻网上没有例子给参考一下. 今天算是找到了,给高手的帖子做个宣传吧. 原网址如下:https://blog.csdn.net/chenlu520 ...
- .NET Core 发布部署问题
运行环境 操作系统 开发工具 frameworks .Net Core SDK 版本 托管运行 本地 ...
- Java框架 高并发系列 1第1天:必须知道的几个概念
https://mp.weixin.qq.com/s?__biz=MzA5MTkxMDQ4MQ==&mid=2648933019&idx=1&sn=3455877c451de9 ...