Given an integer N, express it as the sum of at least two consecutive positive integers. For example:

• 10 = 1 + 2 + 3 + 4

• 24 = 7 + 8 + 9

If there are multiple solutions, output the one with the smallest possible number of summands.

Input

The first line of input contains the number of test cases T. The descriptions of the test cases follow:

Each test case consists of one line containing an integer N (1 ≤ N ≤ 109).

Output

For each test case, output a single line containing the equation in the format:

N = a + (a + 1) + ...+ b

as in the example. If there is no solution, output a single word ‘IMPOSSIBLE’ instead.

Sample Input

3

8

10

24

Sample Output

IMPOSSIBLE

10 = 1 + 2 + 3 + 4

24 = 7 + 8 + 9

问题链接:UVALive6929 Sums

问题分析:需要先考虑一些特殊情况,然后用枚举法,其他都是套路。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++程序如下:

/* UVALive6929 Sums */#include <iostream>
#include <stdio.h>using namespace std;int main()
{int t, n, a, k;scanf("%d", &t);while(t--) {scanf("%d", &n);if(n <= 2)printf("IMPOSSIBLE\n");else if(n % 2) {// 奇数a = n / 2;printf("%d = %d + %d\n", n, a, a + 1);} else {// 2的k次方则不能表示为和a = n;while(a % 2 == 0)a /= 2;if(a == 1) {printf("IMPOSSIBLE\n");continue;}// 等差数列和的通项公式Sk=ka1+k(k-1)d/2,这里d=1// 那么a1=(Sk-k(k-1)/2)/k// 用Sn(程序中的n),求a1和k,这里k>=3for(k=3; ;k++) {a = (n - k * (k - 1) / 2) / k;if(k * a + k * (k - 1) / 2 == n)break;}// 输出结果printf("%d = %d", n, a);for(int i=2; i<=k; i++)printf(" + %d", ++a);printf("\n");}}return 0;
}

UVALive6929 Sums【数学】相关推荐

  1. ICPC程序设计题解书籍系列之五:吴永辉:《数据结构编程实验》(第2版)

    第1章 简单计算 UVALive2362 POJ1004 HDU1064 ZOJ1048 Financial Management[数学+水题] - 海岛Blog - CSDN博客 POJ1552 H ...

  2. 【数学】Natasha, Sasha and the Prefix Sums(CF1204E)

    正题 luogu CF1204E 题目大意 给出序列a,由n个1和m个-1组成,设 f 为最大前缀和和0的最大值,问全排列的 f 之和 解题思路 可以问题转换到平面图上,把1看作往上走,-1看作往下走 ...

  3. 4kyu Sums of Perfect Squares

    4kyu Sums of Perfect Squares 题目背景: The task is simply stated. Given an integer n (3 < n < 109) ...

  4. deap实战_2017中国数学建模大赛_B题_第二题

    简介 补充:本例子仅仅是之前deap类库的一个实战例子,所以先别问我数学建模的事情,我暂时不想回答(还有为毛踩我文章-..我本来就不是写数学建模的--╮(╯▽╰)╭)(2017/10/31) 原问题是 ...

  5. 迭代反投影法代码_程序员的数学笔记3--迭代法

    第三节课程,介绍的是迭代法. 03 迭代法 什么是迭代法 迭代法,简单来说,其实就是不断地用旧的变量值,递推计算新的变量值. 这里采用一个故事来介绍什么是迭代法,这个故事是讲述一个国王要重赏一个做出巨 ...

  6. 程序员的数学笔记3--迭代法

    第三节课程,介绍的是迭代法. 前两节笔记的文章: 程序员的数学笔记1–进制转换 程序员的数学笔记2–余数 03 迭代法 什么是迭代法 迭代法,简单来说,其实就是不断地用旧的变量值,递推计算新的变量值. ...

  7. 神经网络 数学_神经网络与纯数学之间的联系

    神经网络 数学 by Marco Tavora 由Marco Tavora 神经网络与纯数学之间的联系 (Connections between Neural Networks and Pure Ma ...

  8. Numpy Mathematical functions 数学函数

    https://docs.scipy.org/doc/numpy/reference/routines.math.html Trigonometric functions(三角函数) 函数 描述 si ...

  9. LaTex数学之积分、求和和极限

    LaTex数学之积分.求和和极限 积分 可以使用\int_{lower}^{upper} 命令添加积分表达式. 请注意,积分表达式在内联和显示数学模式中可能看起来有些不同. \usepackage{a ...

最新文章

  1. 将NetBIOS名称解析为IP地址的常用方法
  2. (转)函数指针,指针函数,指向函数的指针,返回指针的函数
  3. 3月29日 如何在winform中加入动态系统时间
  4. word自带公式编辑_怎样在word2013中快速插入数学公式
  5. kettle 使用java版本_Kettle最新版本8.X详解
  6. 10拨号拒绝远程连接_ADLS动态拨号vps常见的问题
  7. 经Apache将tomcat转用80port这两个域名
  8. spark任务shell运行_大数据系列:Spark的工作原理及架构
  9. react 怎么获取表格_react学习之js-xlsx导入和导出excel表格
  10. 尚学堂java 参考答案 第九章
  11. OpenShift 4 Tekton - Tekton实现包含Gogs+SonaQube+Nexus+Report+WebHook的Pipeline
  12. thymeleaf的属性优先级
  13. 数据包接收系列 — 上半部实现(网卡驱动)
  14. linux使用wiznote笔记
  15. 计算机软硬件配置在哪里查,如何查看电脑硬件配置信息?
  16. C# 对文件进行MD5计算
  17. 最新消息:愚人节快乐!
  18. hdu 2481 树状数组 双关键字排阻
  19. 输入一个三位数,分别求出x的个位数字,十位数字,百位数字的值。
  20. 通过经纬度获取OpenstreetMap,谷歌地图,高德地图的切片

热门文章

  1. 高并发服务器开源项目,高并发服务器框架详解 - osc_qgfjs4a5的个人空间 - OSCHINA - 中文开源技术交流社区...
  2. .NET——NPOI操作excel
  3. Arcgis Javascript那些事儿(十二)——geometry service几何服务
  4. 使用Box2D制作AS3游戏——2.1a版本——Hello World Box2D .
  5. wordpress PHP合并js,在WordPress函数文件中包含JS(使用PHP)的最佳实践
  6. kafka 新加入副本_Apache-Kafka 核心组件和流程-控制器
  7. 本计算机无法加入家庭组,win10系统无法加入家庭组是怎么回事?
  8. 计算机发展与应用说课,计算机的发展与应用说课稿.doc
  9. android firefox 版本,Android版本Firefox初期预览版发布
  10. nokia 3030 java 应用_诺基亚3030怎么样 :诺基亚3030测评【图解】