Memory Limit: 32 MB |
Ekka and his friend Dokka decided to buy a cake. They bothlove cakes and that's why they want to share the cake after buying it. As thename suggested that Ekka is very fond of odd numbers and Dokka is very fond ofeven numbers, they want to divide the cake such that Ekka gets a share of Nsquare centimeters and Dokka gets a share of M square centimeters where Nis odd and M is even. Both N and M are positive integers.
They want to divide the cake such that N * M = W,where W is the dashing factor set by them. Now you know their dashingfactor, you have to find whether they can buy the desired cake or not.
Input#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
long long n,wa=1,m;
int main(){
int i,j,k,T;
scanf("%d",&T);
for(int u=1;u<=T;u++){
scanf("%lld",&n);
m=n;
wa=1;
if(n%2==0){
while(n%2==0){
n/=2;
wa*=2;
}
printf("Case %d: %lld %lld\n",u,n,wa);
}
else printf("Case %d: Impossible\n",u);
}
return 0;
}
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
long long n,wa=1,m;
int main(){
int i,j,k,T;
scanf("%d",&T);
for(int u=1;u<=T;u++){
scanf("%lld",&n);
m=n;
wa=1;
if(n%2==0){
while(n%2==0){
n/=2;
wa*=2;
}
printf("Case %d: %lld %lld\n",u,n,wa);
}
else printf("Case %d: Impossible\n",u);
}
return 0;
}
Input starts with an integer T (≤ 10000),denoting the number of test cases.
Each case contains an integer W (2 ≤ W < 263).And W will not be a power of 2.
Output
For each case, print the case number first. After that print"Impossible" if they can't buy their desired cake. If they canbuy such a cake, you have to print N and M. If there are multiplesolutions, then print the result where M is as small as possible.
Sample Input | Output for Sample Input |
3 10 5 12 | Case 1: 5 2 Case 2: Impossible Case 3: 3 4 |
给出一个W,要求N*M=W,且N是奇数,M是偶数。求出N和M的值,要求M的值尽可能少。
代码
罗旅洲