当前位置:网站首页>[noip2001 popularization group] the problem of maximum common divisor and minimum common multiple
[noip2001 popularization group] the problem of maximum common divisor and minimum common multiple
2022-07-26 03:07:00 【ceshyong】
Topic link [NOIP2001 Popularization group ] The problem of maximum common divisor and minimum common multiple - Luogu
https://www.luogu.com.cn/problem/P1029
Title Description
Enter two positive integers x0,y0, Find out... That satisfies the following conditions P, Q The number of :
P,Q It's a positive integer. .
requirement P, Q With x0 For the greatest common divisor , With y0 Is the minimum common multiple .
Try to ask for : All possible that meet the conditions P,Q The number of .
Input
Two positive integers in a row x0,y0.
Output
Count one line at a time , It means to find out if the condition is satisfied P, Q The number of .
Sample group
Input
3 60
Output 4Topic ideas
This is a way Water problem A relatively simple topic . First type x0,y0. And then x0,y0 Multiply and store in a variable R in . And then determine R Is it a complete square ( Is the square of a number ), If yes, the answer variable ans--; Then open a double cycle from 1 Cycle to the root R, Judge R Whether it can be cycled by variables i Divisible and i And R/i The greatest common factor of is x0( Just find one ), If the conditions are met ans+=2;
The final output ans that will do .( Note that these variables need to be turned on long long)
As for the greatest common factor , You can directly use __gcd, Or write a special gcd function :
#define ll long long
ll gcd(ll a,ll b)// And __gcd Equivalent
{return (b==0?a:gcd(b,a%b));}// Ternary operator The main program of this topic is as follows :
int getans(int n,int m)
{
int r=n*m,ans=0;
if(n==m) ans--;
for(int i=1;i*i<=r;i++)// This is better than using sqrt(r) faster
if(n%i==0&&gcd(i,n/i)==m) ans+=2;// It can also be used directly here __gcd
return ans;
}AC Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long m,n,k,ans;
ll gcd(ll a,ll b)// And __gcd Equivalent
{return (b==0?a:gcd(b,a%b));}
int main()
{
cin>>m>>n;k=n*m;
if(n==m) ans--;
for(ll i=1;i*i<=k;i++)
if(k%i==0&&gcd(i,k/i)==m) ans+=2;// It can also be used directly here __gcd
cout<<ans;
return 0;
}There are so many questions ( Don't drive O2 I can still live ).
边栏推荐
猜你喜欢

File operation (I) -- File introduction and file opening and closing methods

Safety margin of mass consumption

Information system project managers must recite the core examination site (50). The contract content is not clearly stipulated

循环与分支(一)

MySQL教程:MySQL数据库学习宝典(从入门到精通)

Chen Yili, China Academy of communications technology: cost reduction and efficiency increase are the greatest value of Enterprise Cloud native applications

Personally test five efficient and practical ways to get rid of orders, and quickly collect them to help you quickly find high-quality objects!

Win11隐藏输入法状态栏方法

Autojs cloud control source code + display

Opening method of win11 microphone permission
随机推荐
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)
Hello World driver (II) - primary version
[steering wheel] tool improvement: common shortcut key set of sublime text 4
Win11麦克风权限的开启方法
Win11大小写提示图标怎么关闭?Win11大小写提示图标的关闭方法
The source of everything, the choice of code branching strategy
[SQL] 自连接的用法
Autojs cloud control source code + display
Image recognition (VI) | activation function
JVM内存模型解析
Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
在混合云中管理数据库:八个关键注意事项
Continuous delivery and Devops are good friends
【无标题】
How to correctly calculate the CPU utilization of kubernetes container
How can users create data tables on Web pages and store them in the database
Cycle and branch (I)
【C语言】深入理解 整型提升 和 算术转换
Neo4j import CSV data error: neo4j load CSV error: couldn't load the external resource
小测(一)