Summary_(hdu 2058)_(The Sum Problem)
第一次的話,超時是肯定要的/哭
大致思路:運用等差數列求和公式。
Sn = a1n+n(n-1)d/2. 此題中 d = 1. 即 Sn = a1n+n*(n-1)/2. 根據 n >=1 存在不等式2m<=n*n a1 n = Sn - n(n-1)/2. 只要列舉尋找使a1為整數的n值。
#include <cstdio> #include <iostream> #include <algorithm> #include <string.h> #include <cmath> using namespace std; int main() { long long int a, b, sum; while (cin >> a >> b && (a || b)) { for (int i = sqrt(2 * b); i >0; i--) { int s = b - i * (i - 1) / 2; if (s % i == 0) printf("[%d,%d]\n", s / i, s / i + i-1); } printf("\n",b); } return 0; }
相關推薦
Summary_(hdu 2058)_(The Sum Problem)
第一次的話,超時是肯定要的/哭 大致思路:運用等差數列求和公式。 Sn = a1n+n(n-1)d/2. 此題中 d = 1. 即 Sn = a1n+n*(n-1)/2. 根據 n >=1 存在不等式2m<=n*n a1 n = Sn - n(n
HDU 2058:The sum problem(數學)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
題解報告:hdu 2058 The sum problem
show AC out 求和 pan post 思考 its 題解報告 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 問題描述 給定一個序列1,2,3,...... N,你的工作是計算所有可能的子序列,其子序列的
HDU - 2058 - The sum problem
total orm back spa ins gpo 大於 2.0 ... The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
HDU 2058 - The sum problem(等差數列)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 30916&n
HDU 2058 The sum problem 題解
由題意得: 1.輸入第一個數“n”,作為首項與公差都為“1”的末項 2.輸入第二個數“m”,輸出序列和為“m”的所有子序列,既找到首項“a1”與項數"len" 3.由等差數列求和公式 S=n*(a1+an)/2=a1*n+n*(n-1)*d/2 得:a1*len=m-len*(le
OJ-HDU The sum problem
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Li
杭電2058 The sum problem
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19582 Accept
HDOJ 2058 The sum problem(數學問題)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8287 Accepte
Hdoj.2058 The sum problem【數列】 2015/11/24
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19595 Accep
HDU2058-The sum problem
HDU2058-The sum problem 題目: Problem Description Given a sequence 1,2,3,…N, your job is to calculate all the possible sub-sequences that the su
杭電acm2058————The sum problem(C語言)
原題: Problem Description Given a sequence 1,2,3,……N, your job is to calculate all the possible sub-sequences that the sum of the
The sum problem(高斯公式)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 22089 Acce
HDU2058 The sum problem 題解
空行 miss chmod NPU scrip inpu sample 輸出 -i The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others
hdu 5381 The sum of gcd 2015多校聯合訓練賽#8莫隊算法
names 來看 efi nbsp span ems multipl script there The sum of gcd Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K
NYOJ 927 The partial sum problem 【DFS】+【剪枝】
har int 輸出 amp lines cmp dsm sim pri The partial sum problem 時間限制:1000 ms | 內存限制:65535 KB 難度:2 描寫敘述One day,Tom’s
hdu 5443 The Water Problem(長春網絡賽——暴力)
targe int hdu align follow limit eight math ould 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time L
hdu 5381 The sum of gcd(線段樹+gcd)
const HR LV oid pac vector AR statistic modify 題目鏈接:hdu 5381 The sum of gcd 將查詢離線
HDU 3666 THE MATRIX PROBLEM(差分約束)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 94
hdu 1048 The Hardest Problem Ever(字串處理gets.getline....)
題目: Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. I