1116 - Ekka Dokka
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

3

10

5

12

Case 1: 5 2

Case 2: Impossible

Case 3: 3 4

暴力可以直接过  需要注意的是 n和m都为整数且n为奇数m为偶数

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#define LL long long
#define DD double
#define MAX 10000
using namespace std;
int main()
{
int t;
int m;
LL w,n,i,j;
int ans;
DD ant;
scanf("%d",&t);
int k=1;
while(t--)
{
scanf("%lld",&w);
int flag=0;
printf("Case %d: ",k++);
if(w&1)
{
printf("Impossible\n");
continue;
}
else
{
for(i=2;i<=w/3+4;i++)
{
if(i&1)
continue;
if(w%i==0)
{
n=w/i;
if(n&1)
{
flag=1;
break;
}
}
}
if(flag)
printf("%lld %lld\n",n,i);
else
printf("Impossible\n");
}
}
return 0;
}

  

light oj 1116 - Ekka Dokka的更多相关文章

  1. Light OJ 1116

    基础数学:.. #include<bits/stdc++.h> using namespace std; typedef unsigned long long ULL; int main( ...

  2. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  3. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  4. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  5. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  6. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  7. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  8. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  9. Jan's light oj 01--二分搜索篇

    碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...

随机推荐

  1. HDU4539+状态压缩DP

    /* 题意:n行m列的矩阵,1表示可以放东西,0表示不可以.曼哈顿距离为2的两个位置最多只能有一个位置放东西. 问最多放多少个东西. */ #include<stdio.h> #inclu ...

  2. redisb并发访问慢出现的问题

    最近项目一上线,就问题颇多,本地测试,ok,上线后,大用户量的时候,顶不住.用了一个礼拜的时间发现的问题,总结下来. 项目是netty4.0,reids2.8,nginx等框架.目前是4台proxy服 ...

  3. 转XMLHelper

    http://www.cnblogs.com/lixyvip/archive/2009/09/16/1567929.html using System; using System.Collection ...

  4. 【HDOJ】1699 The comment in cpp

    注意测试数据12/*hduacm// abcd结果是1/*hduacm// ABCD /* 1699 */ #include <iostream> #include <sstream ...

  5. Hibernate一对多和多对一关系详解 (转载)

    :双向一对多关系,一是关系维护端(owner side),多是关系被维护端(inverse side).在关系被维护端需要通过@JoinColumn建立外键列指向关系维护端的主键列.     publ ...

  6. Hashtable与HashMap区别(2)

    提到hashtable,先要澄清两个问题hashCode与equals().Hashtable有容量和加载因子,容量相当于桶,因子相当于桶里的对象.而hashCode我们可以把它理解为桶的序号,所以H ...

  7. poj 1924 Paths on a Grid(组合数学)

    题目:http://poj.org/problem?id=1942 题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有 ...

  8. poj3671

    首先容易想到的是LIS,但是n<=30000,所以肯定要优化: 壮哉单调队列又登场了: 然后再找一个最长不上升序列并求两者最大值即可,复杂度O(n logn); 应该说这是解题通法了,但再回头看 ...

  9. 使用HQL查询

    HQL是Hibernate Query Language的缩写,语法很想SQL,但是HQL是一种面向对象的查询语言.SQL的操作对象是数据列.表等数据库对象,而HQL操作的是类.实例.属性. HQL查 ...

  10. PHP分次读取xls

    <?php $sourceFile = "1.tmp"; //要下载的临时文件名 $outFile = "用户订单.xls"; //下载保存到客户端的文件 ...