UVA_11526 H(n)
2008-10-24 14:06
253 查看
思路就是找到n/i结果相同的,跳过并累加
注意的是数据十分变态,居然还有n<0的数。。。无语。。。数据量也是大的吓人....
ProblemG[/b]
H(n)[/b]
Input:[/b]StandardInput
Output:[/b]StandardOutput
WhatisthevaluethissimpleC++functionwill
return?
longlongH(intn){
longlong
res=0;
for(inti
=1;i<=n;i=i+1){
res=
(res+n/i);
}
return
res;
}
Input
ThefirstlineofinputisanintegerT(T<=1000)
thatindicatesthenumberoftestcases.EachofthenextTlinewillcontaina
singlesigned32bitintegern.
Output
Foreachtestcase,outputwillbeasinglelinecontainingH(n).
Problem-setter:Md.ArifuzzamanArif
SpecialThanks:ShahriarManzoor
#include<iostream>
#include<cmath>
usingnamespacestd;
longlongH(longlongn){
if(n<=0)return0;
longlongres=n;
longlongi,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;
}
}
returnres;
}
intmain()
{
longlongn,t;
cin>>t;
while(t--)cin>>n,cout<<H(n)<<endl;
return0;
}
注意的是数据十分变态,居然还有n<0的数。。。无语。。。数据量也是大的吓人....
ProblemG[/b]
H(n)[/b]
Input:[/b]StandardInput
Output:[/b]StandardOutput
WhatisthevaluethissimpleC++functionwill
return?
longlongH(intn){
longlong
res=0;
for(inti
=1;i<=n;i=i+1){
res=
(res+n/i);
}
return
res;
}
Input
ThefirstlineofinputisanintegerT(T<=1000)
thatindicatesthenumberoftestcases.EachofthenextTlinewillcontaina
singlesigned32bitintegern.
Output
Foreachtestcase,outputwillbeasinglelinecontainingH(n).
SampleInputOutputforSampleInput
2 5 10 | 10 27 |
SpecialThanks:ShahriarManzoor
#include<iostream>
#include<cmath>
usingnamespacestd;
longlongH(longlongn){
if(n<=0)return0;
longlongres=n;
longlongi,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;
}
}
returnres;
}
intmain()
{
longlongn,t;
cin>>t;
while(t--)cin>>n,cout<<H(n)<<endl;
return0;
}
相关文章推荐
- uva 11526 H(n) (数论)
- UVA 11526 H(n)
- UVa 11526 - H(n)
- H(n) UVA - 11526
- uva 11526 H(n)(公式优化)
- UVA 11526 H(n)
- [UVA 11526]H(n)[数学]
- (UVA - 11526) H(n)
- uva 11526计算n/1+n/2+...+n/n(整除)
- UVA 11526 - H(n)
- UVA-11526H(n)(数论)
- uva 11526
- UVa 11526 - H(n)
- H(n)(Uva 11526)
- uva 11526 H(n)
- UVA 11526(p344)----H(n)
- UVa 11526 H(n)
- UVa 11526 - H(n) [数学]
- UVa 11526 - H(n)
- 【数论,找规律】Uva 11526 - H(n)