[Codeforces Round #164 (Div. 2)]B. Buttons
地址:http://codeforces.com/contest/268/problem/B
找规律,有公式,累加即可
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,ans; 6 7 int main() 8 { 9 ios::sync_with_stdio(false); 10 int i,j; 11 cin>>n; 12 for(i=n-1,j=1;i>=0 && j<=n;i--,j++) 13 { 14 if(i==0) ans+=j; 15 else 16 { 17 ans+=i*j; 18 } 19 } 20 cout<<ans; 21 return 0; 22 }