当前位置:网站首页>[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 ).
边栏推荐
- Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
- An article allows you to understand the relevance of cloud native containerization
- Hello World driver (II) - primary version
- Digital commerce cloud DMS dealer management system solution: DMS system realizes business Omni channel and sales data collection
- [SQL] CASE表达式
- YOLOv3: An Incremental Improvement
- Influence of middle tap change on ZVS oscillation circuit
- VR panoramic shooting and production of business center helps businesses effectively attract people
- Parallelloopbody in opencv
- [translation] announce Vites 13
猜你喜欢

Image recognition (VI) | activation function

Vofa+ serial port debugging assistant

如何用U盘进行装机?

MySQL tutorial: MySQL database learning classic (from getting started to mastering)

中国信通院陈屹力:降本增效是企业云原生应用的最大价值
![[translation] cloud like internal load balancer for kubernetes?](/img/e5/f003ebed05a94d2936cfef5617f745.jpg)
[translation] cloud like internal load balancer for kubernetes?

Arthas download and startup

Win11 method of changing disk drive letter

How to design automated test cases?

Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 1)
随机推荐
事半功倍:学会WEB性能测试用例设计模型
【C语言】深入理解 整型提升 和 算术转换
Dataframe sorting: datetime format splitting; Delete a specific line; Group integration.
The difference between the world wide web, the Internet and the Internet
.net serialize enumeration as string
ENVI_ Idl: create HDF5 file and write data (take writing GeoTIFF file to HDF file as an example) + detailed parsing
Parallelloopbody in opencv
[NOIP2001 普及组]装箱问题
【无标题】
STM32——串口学习笔记(一个字节、16位数据、字符串、数组)
STM32 - DMA notes
[translation] cloud like internal load balancer for kubernetes?
Chen Yili, China Academy of communications technology: cost reduction and efficiency increase are the greatest value of Enterprise Cloud native applications
Case: using kept+haproxy to build a Web Cluster
Type the URL to the web page display. What happened during this period?
Opencv 以指定格式保存图片
The source of everything, the choice of code branching strategy
经典面试问题——OOP语言的三大特征
(9) Attribute introspection
多线程编程