注意的是数据十分变态,居然还有n<0的数。。。无语。。。数据量也是大的吓人....
Problem G
H(n)
Input: Standard Input
Output: Standard Output
What is the value this simple C++ function will return?
long long H(int n){
long long res = 0;
for( int i = 1; i <= n; i=i+1 ){
res = (res + n/i);
}
return res;
}
Input
The first line of input is an integer T ( T <= 1000 ) that indicates the number of test cases. Each of the next T line will contain a single signed 32 bit integer n.
Output
For each test case, output will be a single line containing H(n).
Sample Input Output for Sample Input
2 5 10
| 10 27
|
Problem-setter: Md. Arifuzzaman Arif
Special Thanks: Shahriar Manzoor- #include <iostream>
- #include <cmath>
- using namespace std;
- long long H(long long n){
- if(n<=0)return 0;
- long long res =n;
- long long i,pre=n,tmp;
- for(i=2;i<=n;i++)
- {
- res+=(tmp=n/i);
- if(tmp!=pre)
- {
- res+=(n/tmp-i)*(tmp);
- i=n/tmp;
- pre=tmp;
- }
- }
- return res;
- }
- int main()
- {
- long long n,t;
- cin>>t;
- while(t--)cin>>n,cout<<H(n)<<endl;
- return 0;
- }