博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Light Oj 1116
阅读量:5336 次
发布时间:2019-06-15

本文共 2008 字,大约阅读时间需要 6 分钟。

Ekka Dokka

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit
Status
Description
Ekka and his friend Dokka decided to buy a cake. They both love cakes and that's why they want to share the cake after buying it. As the name suggested that Ekka is very fond of odd numbers and Dokka is very fond of even numbers, they want to divide the cake such that Ekka gets a share of N square centimeters and Dokka gets a share of M square centimeters where N is 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 dashing factor, you have to find whether they can buy the desired cake or not.
Input
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 can buy such a cake, you have to print N and M. If there are multiple solutions, then print the result where M is as small as possible.
Sample Input
3
10
5
12
Sample Output
Case 1: 5 2
Case 2: Impossible
Case 3: 3 4

/****************************************     author   :   Grant Yuan     time     :   2014.8.6     algorithm:   数论     source   :   Light Oj 1116     explain  :   如果这个数为奇数则一定不可能;                  如果为偶数,要保证所得偶数最小,则奇数要最大                  用原来的数不断除以2,直到所得的数为奇数,再用                  原数除以奇数便可得到偶数;                  *****************************************/#include
#include
#include
#include
#include
using namespace std;long long n,a,b,c;int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a); if(a%2) printf("Case %d: Impossible\n",i); else{ c=a; while(c%2==0) { c=c/2;} b=a/c; printf("Case %d: %lld %lld\n",i,c,b); } } return 0;}

 

转载于:https://www.cnblogs.com/codeyuan/p/4254459.html

你可能感兴趣的文章
Ubuntu改坏sudoers后无法使用sudo的解决办法
查看>>
NEYC 2017 游记
查看>>
[搬运] 写给 C# 开发人员的函数式编程
查看>>
Python之旅Day14 JQuery部分
查看>>
core--线程池
查看>>
redux-effect
查看>>
Swift和OC混编
查看>>
Android轻量级的开源缓存框架ASimpleCache
查看>>
他山之石:加载图片的一个小问题
查看>>
shell - 常识
查看>>
mssql sqlserver 使用sql脚本 清空所有数据库表数据的方法分享
查看>>
分层图最短路【bzoj2763】: [JLOI2011]飞行路线
查看>>
linux下编译复数类型引发的错误:expected unqualified-id before '(' token
查看>>
codeforces 1041A Heist
查看>>
字典常用方法
查看>>
Spring Cloud Stream消费失败后的处理策略(三):使用DLQ队列(RabbitMQ)
查看>>
bzoj1048 [HAOI2007]分割矩阵
查看>>
Java中的编码
查看>>
PKUWC2018 5/6
查看>>
As-If-Serial 理解
查看>>