当前位置:网站首页>[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 ).
边栏推荐
- Teach you to rely on management hand in hand
- Parallelloopbody in opencv
- The difference between the world wide web, the Internet and the Internet
- Hello World driver (II) - primary version
- Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
- 一篇文章让你理解 云原生 容器化相关
- C language layered understanding (C language function)
- Nahamcon CTF 2022 babyrev reverse analysis
- 小测(一)
- File operation (I) -- File introduction and file opening and closing methods
猜你喜欢

canvas——绘制文本——饼图的修改

STM32——DMA笔记

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

软件测试岗:阿里三面,幸好做足了准备,已拿offer

How to correctly calculate the CPU utilization of kubernetes container

ES6 set and map

VOFA+ 串口调试助手

YOLOv3: An Incremental Improvement

Managing databases in a hybrid cloud: eight key considerations

Opencv 在图像上进行标注(画框+写字)
随机推荐
Autojs cloud control source code + display
The source of everything, the choice of code branching strategy
小测(一)
Skill list of image processing experts
Nahamcon CTF 2022 babyrev reverse analysis
如何正确计算 Kubernetes 容器 CPU 使用率
图像识别(六)| 激活函数
[translation] safety. Value of sboms
GoLang日志编程系统
26 points that must be paid attention to for stability test
[SQL] 自连接的用法
事半功倍:学会WEB性能测试用例设计模型
C language layered understanding (C language function)
Extended Physics-InformedNeural Networks论文详解
canvas——绘制文本——饼图的修改
(九)属性自省
[NOIP2001 普及组]装箱问题
经典面试问题——OOP语言的三大特征
Information system project managers must recite the core examination site (50). The contract content is not clearly stipulated
The difference between the world wide web, the Internet and the Internet