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

Copy
12 18

Sample Output 1 Copy

Copy
3

1212 and 1818 have the following positive common divisors: 112233, and 66.

11 and 22 are coprime, 22 and 33 are coprime, and 33 and 11 are coprime, so we can choose 1122, and 33, which achieve the maximum result.


Sample Input 2 Copy

Copy
420 660

Sample Output 2 Copy

Copy
4

Sample Input 3 Copy

Copy
1 2019

Sample Output 3 Copy

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题】【判断素数的模板+求一个数的因子的模板】的更多相关文章

  1. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  2. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  3. AtCoder Beginner Contest 050 ABC题

    A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...

  4. AtCoder Beginner Contest 069 ABCD题

    题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...

  5. AtCoder Beginner Contest 070 ABCD题

    题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...

  6. AtCoder Beginner Contest 057 ABCD题

    A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...

  7. AtCoder Beginner Contest 215 F题题解

    F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...

  8. AtCoder Beginner Contest 051 ABCD题

    A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...

  9. AtCoder Beginner Contest 137 D题【贪心】

    [题意]一共有N个任务和M天,一个人一天只能做一个任务,做完任务之后可以在这一天之后的(Ai-1)天拿到Bi的工资,问M天内最多可以拿到多少工资. 链接:https://atcoder.jp/cont ...

随机推荐

  1. [tensorflow] 入门day1-数据整理与展示

    tensorflow真是一个我绕不开的坑(苍天饶过谁.jpg) 其实tensorflow1和2的差别挺大的,暂时从1入坑,2的话之后简单过一下. tf2中更改的函数(供参考):https://docs ...

  2. [Vue]vue-loader作用

    一.vue文件 vue文件是一个自定义的文件类型,用类HTML语法描述一个vue组件,每个.vue组件包含三种类型的顶级语言快< template>< script>< ...

  3. 【SQL Server性能优化】运用SQL Server的全文检索来提高模糊匹配的效率

    原文:[SQL Server性能优化]运用SQL Server的全文检索来提高模糊匹配的效率 今天去面试,这个公司的业务需要模糊查询数据,之前他们通过mongodb来存储数据,但他们说会有丢数据的问题 ...

  4. 定时任务FluentScheduler

    1.Nuget 安装包 2.创建3个不同的任务 public class MyJob : IJob { void IJob.Execute() { Trace.WriteLine("现在时间 ...

  5. Ajax中解析Json的两种方法

    eval(); //此方法不推荐 JSON.parse(); //推荐方法 一.两种方法的区别 我们先初始化一个json格式的对象: var jsonDate = '{ "name" ...

  6. c#基础知识梳理(二)

    上期回顾 - https://www.cnblogs.com/liu-jinxin/p/10818256.html 一.变量 一个变量只不过是一个供程序操作的存储区的名字.在 C# 中,每个变量都有一 ...

  7. 关于js异步的一些知识点

    1,什么是单线程,和异步有什么关系 单线程-只有一个线程,只能做一件事 单线程的原因:避免DOM 渲染的冲突 浏览器需要渲染DOM JS 可以修改DOM 结构 JS 执行的时候,浏览器DOM 渲染会暂 ...

  8. c去除空格 小写转大写

    int isalnum(int c); //字母或数字 int isalpha(int c); //英文字母 int isascii(int c); //ASCII 码字符(0 到127) int i ...

  9. BeginInvoke异步线程

    this.BeginInvoke(new Action(() => { dataGridView1.DataSource = BLLBillConsume.BllGetClearMarketLo ...

  10. Linux命令——shutdown、halt、poweroff、reboot、cal、date

    shutdown shutdown在关机的时候会通知所有用户 shutdown –r now 现在重启 shutdown now 现在关机 shutdown +5 过5分钟关机 shutdown –c ...