G - Ekka Dokka

https://vjudge.net/contest/240973#problem/G

基础题水题:

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

题意:
t组
对于每一组,给出w(2<=w<=2^63),
问是否存在正数n,m,n奇m偶,满足n*m=w,没有输出...
若有输出n,m,若有多组则输出让m尽可能小的那一组

有一点没有注意:奇数*偶数=偶数,所以奇数一定不可能

偶数一定可以(可分解成1乘本身)

代码:

#include <stdio.h>
#include <math.h>
typedef long long ll;
int main()
{ll t,w,k=0,i;scanf("%lld",&t);while(t--){k++;scanf("%lld",&w);if(w%2!=0)//奇数时一定不存在 printf("Case %d: Impossible\n",k);else{for(i=2;i<=w;i=i+2){if(w%i==0){if((w/i)%2!=0){printf("Case %d: %lld %ld\n",k,w/i,i);break;}}}}}} 

算术基本定理+容斥-17级暑假集训相关推荐

  1. 2019牛客国庆集训派对day2 K 2018(容斥)

    链接:https://ac.nowcoder.com/acm/contest/1107/K 来源:2019牛客国庆集训派对day2 题目描述   Given a, b, c, d, find out ...

  2. 2014暑假ACM13级一批集训内容

    2014 这个暑假,我大一的暑假来吧!!! 2014暑假ACM13级一批集训内容 集训期间时间安排: 周一到周六 上午:8:00-11:30 下午:2:00-5:30 晚上7:00-9:30 周日自由 ...

  3. jzoj5498 【清华集训2017模拟12.10】大佬的难题 巧妙容斥

    分治容斥都想了,但想不出正解.. 先说60分的吧 先排序a,然后在b,c上分治. 我们将b两边归并的同时,用数据结构维护b比当前小的c都在哪些地方. 这样就是n log2 n 再说说正解 记a[x] ...

  4. “玲珑杯”线上赛 Round #17 河南专场 B:震惊,99%+的中国人都会算错的问题(容斥计算)...

    传送门 题意 略 分析 是一道稍微变形的容斥题目,容斥一般的公式 \[ans=\sum_iAi-\sum_{i<j}{Ai∩Aj}+\sum_{i<j<k}{Ai∩Aj∩Ak}+.. ...

  5. 容斥定理与鸽巢定理(抽屉定理)

    定义 在计数时,必须注意没有重复,没有遗漏.为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时 ...

  6. HDU - 5468 Puzzled Elena —— 容斥

    题意: 每个点的子树上有几个节点与该节点的权值互质 思路: 首先要明白怎么求一个集合中有多少个数与n互素 将集合中的数用算术基本定理分解,记录每个数能形成的所有因子的个数,然后将n分解进行容斥,可以求 ...

  7. Luogu P4336 [SHOI2016]黑暗前的幻想乡(容斥,矩阵树定理,子集反演)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Luogu P4336 [SHOI2016]黑暗前的幻想乡(容斥,矩阵树定理) Problem n≤1 ...

  8. BZOJ2301:[HAOI2011]Problem b(莫比乌斯反演,容斥)

    Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...

  9. ACM-ICPC 2018 沈阳赛区网络预赛 Spare Tire(容斥+公式推)

    A sequence of integer \lbrace a_n \rbrace{an​} can be expressed as: \displaystyle a_n = \left\{ \beg ...

最新文章

  1. 中国研制出首款搭载寒武纪AI芯片的人工智能服务器
  2. GnuPG如何安全地分发私钥(1)GnuPG的用法
  3. 云计算技术 — 云原生
  4. 5月下旬全球域名解析服务商TOP15:万网居第15
  5. 数字图像处理(一)2
  6. wampserver3.0.6 外网 不能访问
  7. web.config 指定的默认页失效
  8. linux中dump文件怎么生成,linux下设置core dump文件生成的方法
  9. 除了php云和骑士还有什么_骑士CMS是什么开源程序
  10. 用了这个工具,我设计的PCB再也没出过问题
  11. 基于Selenium的Web UI自动化实现(java)
  12. 电机正反转的远程计算机控制,plc控制电机正反转原理图
  13. Python利用百度地图抓取商家地址
  14. 百度快照劫持的表现及解决方法
  15. python发送qq文件_怎么用qq邮箱发文件-十分钟教你使用Python发送邮件(复制可用)...
  16. 百战归来再读书--一个程序员的2008年阅读书目
  17. EMC组建BRS部门 让备份不再成为困扰
  18. 关于AQS中enq( )方法CAS操作的疑惑
  19. Java中值得注意的『运算符、逻辑控制、输入输出』
  20. 操作系统——IO设备管理

热门文章

  1. 标签 align 属性
  2. 如何看待2023届秋招形势?
  3. 电脑桌面图标右下角显示有白色文本框
  4. 《巨人不死密码》读书笔记
  5. node.js+uni计算机毕设项目基于微信小程序的网上购物系统(程序+小程序+LW)
  6. 解决文件上传时状态码413错误
  7. JS - 实现时间选择器
  8. dataflow_Java中的Cloud Dataflow快速入门
  9. 为什么说CPU频率远高于内存频率(CPU3Ghz、内存2666Mhz)
  10. 颜色不变性算法及应用总结