被C题坑了,就没有再看D题,还是比较有意思的。
Problem Statement
You are given integers N and M.
Consider a sequence aa of length N consisting of positive integers such that a1+a2+...+aN = M. Find the maximum possible value of the greatest common divisor of a1,a2,...,aN.
Constraints
- All values in input are integers.
- 1≤N≤10^5
- N≤M≤10^9
思路:假设最大公约数为g,则M=tg(存在t为正整数),a1=t1g,a2=t2g...an=tng(存在t1,t2...tn为正整数),于是只需要找出来能被M整除结果大于N的最大数即可。
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=m/n;i>=1;i--)
{
if(m%i==0)
{
int t=m/i;
if(t>=n)
{
cout<<i<<endl;
break;
}
}
}
}