https://blog.csdn.net/opm777/article/details/25726221
The European Cup final is coming. The past two World Cup winners, Spain and Italy, will contest the decider at Kiev's Olympic Stadium. Italy-Spain Euro final promises to be clash of polar opposites, so it's difficult to say which team will win.
Now there are M fans in ZJU, N of them support Italy. Suppose you are the president of the students' union and you support Italy. You can divide these M fans into s1 groups(Level 1). More than half of the group(Level 1) support Italy ,than you can say it seems all the M fans support Italy. You can also divide each group(Level 1) into s2 groups(Level 2). More than half of the group(Level 2) support Italy ,than you can say this group(Level 1) support Italy. ... .You can also divide each group(Level i) into s(i+1) groups(Level i+1). More than half of the group(Level i+1) support Italy ,than you can say this group(Level i) support Italy. To be fair, every group(Level i) has the same number of person. Can you find an suitable way to arrange these N person so that all these M fans seem to support Italy.
Input
Mutiple test cases, process to the end of file.
Each case has a single line with two integer M , N (1<=M,N<=100000000).
Output
For each case:
The firt line output Yes if you can do the task or No for not. The second line output the minimum person you need.
Sample Input
4 3 12 5
Sample Output
Yes 3 No 6
假设这n个人所在
比方拆成m组,假设这m组中多于一半是
转载自:left_hand
发现有些情况不能表达。就是
只是開始开数组老是
#include<iostream>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
//const int maxn=1000005;
//int visi[maxn];
map <int,int> mq;
int dfs(int x)
{
if(mq.count(x)>0)
return mq[x];
int mi=x/2+1;
for(int k=2;k<=sqrt(x+0.5);k++)
{
if(x%k==0)
{
mi=min(mi,(k/2+1)*dfs(x/k));
mi=min(mi,(x/k/2+1)*dfs(k));
}
}
mq[x]=mi;
return mi;
}
int main()
{
int m,n;
while(cin>>m>>n)
{
mq.clear();
//memset(visi,0,sizeof(visi));
int ans=dfs(m);
//int ans=0;
if(ans>n)
printf("No
%d
",ans);
else
printf("Yes
%d
",ans);
}
return 0;
}
/*
4 3
12 5
*/