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.
Mutiple test cases, process to the end of file.
Each case has a single line with two integer M , N (1<=M,N<=100000000).
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.
4 3 12 5
Yes 3 No 6
#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\n%d\n",ans); else printf("Yes\n%d\n",ans); } return 0; } /* 4 3 12 5 */