HDU 2058 The sum problem
来源:互联网 发布:java多线程锁的概念 编辑:程序博客网 时间:2024/04/28 17:10
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=2058
题目大意:
求1~n中和等于m的子序列
题解:
sub(a,b)为a到b序列的和,由高斯公式 sub(a,b)=(b+a)*(b-a+1)/2
假设输入为 20 10
m=10, 2*m的因式 x*y 有 4*5 2*10 1*20
由y=b+a;x=b-a+1;即可求得a,b的值。
(这题n压根不用考虑就能AC)
代码:
#include<stdio.h>#include<math.h>int main(){int n,m;while(~scanf("%d%d",&n,&m),n+m){int i;m=2*m;for(i=(int)sqrt((double)m);i>=1;i--){int x,y;int a,b;if(m%i==0){y=i>(m/i)?i:(m/i);x=i<(m/i)?i:(m/i);if((x+y-1)%2==0&&(y-x+1)%2==0){a=(y-x+1)/2;b=(x+y-1)/2;printf("[%d,%d]\n",a,b);}}}printf("\n");}return 0;}
0 0
- hdu 2058 The sum problem
- hdu 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- hdu---2058The sum problem
- The sum problem hdu 2058
- hdu 2058 The sum problem
- HDU 2058 The Sum Problem
- HDU-2058 The sum problem
- hdu 2058 The sum problem
- HDU 2058 The sum problem
- hdu 2058 The sum problem
- The sum problem hdu 2058
- 第一个scala程序
- 重火離 (易經大意 韓長庚)
- C++:函数与递归 Function and Recursion
- Android Training精要(一)ActionBar上级菜单导航图标
- 使用subversion实现虚拟机中linux和windows宿主机代码共享管理
- HDU 2058 The sum problem
- 第一章 基础知识
- [Cookie]wget下载jdk 为什么需要加cookie
- [多重背包]HOJ 1141/HDU 1059 Dividing
- 重水習坎 (易經大意 韓長庚)
- javaScript 面向对象-对象
- Ubuntu的学习(四)『文件权限』
- Linux 引导过程内幕
- Android Training精要(二)開啟ActionBar的Overlay模式