Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
推不出数学公式,不过觉得我的方法也不错。#include<stdio.h> int main() { freopen("D:/ACMData.txt","r",stdin); int n; for(scanf("%d",&n);n;scanf("%d",&n)) { int i=1; int k; long sum = n; for(k = i; k<n; i++, k = (1+i)*i/2)//k为等差数列前n项和 { sum += n-k; } printf("%d %ld\n",n,sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator