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. 【转】SpringMVC框架实现后端向前端传数据

    首先还是页面userAdd.jsp.它既是发出请求的页面,也是接收返回结果的页面: <%@ page language="java" import="java.ut ...

  2. TZOJ2882: 美食节之感恩父母

    #include<stdio.h> int main() { ],b[],i,j,max,m,t1,t2,t3; while(scanf("%d",&m),m) ...

  3. 关于Python的导入覆盖解决办法

    这种问题一般来说还是不会引起的,可能会出现在datetime和time这样类型的模块中. 例如: import datetime from datetime import datetime 如果写在一 ...

  4. (八)mybatis之多对多

    一.需求分析 需求:查询所有用户的信息以及每个用户所属的组的信息 分析:一个用户可以有多个组,一个组也可以由多个用户. 多对多,可以设置一张中间表,该表存放的是用户表和组表的对应关系. 二.创建数据库 ...

  5. Visual Studio 最新插件

    Resharper 最新版本下载 https://www.jetbrains.com/resharper/ 破解方法 安装完成后,打开vs  弹出注册窗口选择Activate>License S ...

  6. Rider开发开发.NET Framework 4.5项目遇到的一些问题

    使用rdier自带resharper功能,蛮爽的但是编译旧的项目时一直报错:Invalid option 'portable' for /debug; must be full or pdbonly' ...

  7. class类 - static

    不需要实例化类,即可直接通过该类来调用的方法,即称之为"静态方法".将类中的方法设为静态方法也很简单,在方法前加上static关键字即可.这样该方法就不会被实例继承! class ...

  8. 原生js上传图片遇到的坑(axios封装)

    后台给我写了一个上传图片的接口,自己用form表单测试成功 接口可以正常跳转 测试的代码: <!doctype html> <html lang="en"> ...

  9. javascript新特性

    让我们看看javascript中的一些新特性.本文将介绍它们的语法和相关链接,以帮助读者及时了解它们的进展.我们将通过编写一个小测试项目来演示如何快速使用这些新功能! 关于提案 提案分为五个阶段.有关 ...

  10. LeetCode 【1】 Two Sum --001

    5月箴言 住进布达拉宫,我是雪域最大的王.流浪在拉萨街头,我是世间最美的情郎.—— 仓央嘉措 从本周起每周研究一个算法,并以swift实现之 001 -- Two Sum (两数之和) 题干英文版: ...