This question is called the p1307 black square on vijos, but I prefer wikioi because he has better details ......
Description
Description
One day seekdreamer went out to play and saw that the floor on the street was composed of many small squares. Suddenly, I was wondering how many squares I Wanted To summarize ......
So he tried to count the number and finally learned that the total side length of a square is N. Your task is to find out the number of squares with at least one side length.
Input description
Input description
A natural number n.
Output description
Output description
An integer, that is, the total number of squares.
Sample Input
Sample Input
2
Sample output
Sample output
5
Data range and prompt
Data size & hint
(0 ≤ n ≤32767)
Thinkings
Although the range given by this question is only int, It is terrible to multiply! C ++ does not enable long. Using Int Is the rhythm of death... Wa: 70 times here
The formula or enumeration can all be dropped and all have code ..
Code Codes
program ss; var all:qword; n,d,i:longint; begin readln(n); all:=0; for i:=0 to n-1 do begin d:=n-i; d:=d*d; all:=all+d; end; writeln(all); end.
The above is the formula of Pascal ..
The formula of C will not be put, but it will be the same...
#include<iostream>using namespace std;int main(){ long long n,d,all,i; cin>>n; all=0; for (i=1;i<=n;i++) { all+=(n-i+1)*(n-i+1); } cout<<all<<endl;}
This is an enumeration algorithm of C ++. (⊙ v ⊙) Well, most people may think of this as a habit ....