2015年3月26日 星期四

★1 23631:Feynman

題目資料:http://gpe.acm-icpc.tw/showproblem.php?cid=5&probid=23631
公式:
1. K=((K*(K+1)*(2*K+1))/6 平方和公式
程式碼:

------------------------------------------------------------------------------------------
#include <iostream>
int main()
{
using namespace std;
int x;
long out; //避免輸出太大

cin >> x;
while((x <= 100) && (x >= 1)) //輸入的數值要介於1<=X<=100
{
out = (x * (x + 1) * ((2 * x) + 1))/6;        //公式
cout << out << endl;
cin >> x;
}
return 0;
}
------------------------------------------------------------------------------------------

沒有留言:

張貼留言

歡迎指教或發問