Mathematical scum hiding =-=
Fortunately, this question is about high school knowledge... the sum of series ..
At the beginning, I thought of a 2-layer method with the largest chest and no brain. Even if I saw this data, I thought it would be <32 bits very big ..
I think about it again. I don't think I can find it in deep search...
Just to simplify the formula.
X1 + X2 + X3 +... + Xn Special tolerances d = 1 so X2 = X1 + 1x3 = X1 + 2 xn = X1 + n-1
Then it can be reduced to X1 * n + N * (n-1) /2 = sum here n is the index Column Length Sum is the question for us to write n letters is not good, forgive me =-= N * (n-1)/2 is 0, 1, 2, 3, 4 .... the sum of N
OK. I thought it was AC.
But I am still tle... I am about it ..
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 cin.sync_with_stdio(false); 7 int n , ans , temp; 8 while( cin >> n ) 9 {10 ans = 0;11 for( int i = 2 ; i<=n ; i++ )12 {13 temp = i*(i-1)/2;14 if(n>temp)15 {16 if( (n-temp)%i == 0 )17 ans ++;18 } 19 }20 cout << ans << endl;21 }22 return 0;23 }
In fact, you can also see that I have another judgment on if (n> temp) in for, because some of them will be larger than N, and then subtract is negative, but the same is true (n-Temp) % I = 0 so I need to cut it
However, if I cut it like this, the for side will continue to run.
In fact, it is very simple. I just need to add an else break;
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 cin.sync_with_stdio(false); 7 int n , ans , temp; 8 while( cin >> n ) 9 {10 ans = 0;11 for( int i = 2 ; i<=n ; i++ )12 {13 temp = i*(i-1)/2;14 if(n>temp)15 {16 if( (n-temp)%i == 0 )17 ans ++;18 } 19 else20 break; 21 }22 cout << ans << endl;23 }24 return 0;25 }
View code
Today:
Thousands of love types in the world
But there is never one that can be reused.