Time Limit: 20 Secphp
Memory Limit: 256 MBios
題目鏈接ide
http://www.lydsy.com/JudgeOnline/problem.php?id=1968spa
Descriptionip
Inputci
只有一行一個整數 N(0 < N < 1000000)。get
Outputstring
只有一行輸出,爲整數M,即f(1)到f(N)的累加和it
Sample Inputio
3
Sample Output
5
HINT
題意
題解:
直接ans+=n/i就行了
表示這個數對總體的貢獻值是多少
代碼:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <bitset> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 200051 #define mod 10007 #define eps 1e-9 int Num; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** int main() { int n=read(); ll ans=0; for(int i=1;i<=n;i++) ans+=n/i; cout<<ans<<endl; }