Gaussian Formula topic Details:
In elementary school, Gauss invented the arithmetic progression summation formula: 1+2+. +100=5050. Now the problem is to give you a positive integer n, and ask you how many consecutive positive integers can he represent? (self-calculation).
Input format:
Multiple sets of data, one row per set of data, and a positive integer n.
0<n<2000000000
Output format:
A row of data for each group, including a positive integer, representing the result.
Answer instructions:
Input example
5
120
Output Example:
2
4
Explain:
5=2+3=5
120=1+2+...+15=22+23+24+25+26=39+40+41=120
First Draft Code:
/*3:3, 1+2=34: 4, 5:5, 2+3=56:6, 1+2+3=6 7: 7, 3+4=7 8:8, 9:9, 4+5=9, 2+3+4=910: 10, 1+2+3+4=10 Analysis: input n set s,x ( X starts from S continuous number addition equals N, for example: 10=1+2+3+4 in N:10 s:1 x=4) Then there is a summation formula:
Post-AC code:
#include "stdio.h" #include "math.h" int main () {int count;long long x,n;while (scanf ("%i64d", &n)!=eof) {double s=n; for (count=0,x=2;s>=1;x++) {if (s+0.5) ==s) {count++;//printf ("%d > x:%d s:%d\n", count,x-1, (int) s);} S= (Double) n/x+ (1-x)/2.0;} printf ("%d\n", count);//break;} return 0;}
Note: Data in a program with a large data type of int control may overflow during calculation
CSDN Challenge Programming Exchange Group:372863405
CSDN Programming Challenge--"Gauss formula"