来自FallDream的博客,未经允许,请勿转载,谢谢。
n<=1000000
这个嘛 直接枚举因数就好啦。
#include<iostream> #include<cstdio> #define MN 1000000 #define ll long long using namespace std; inline int read() { int 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 n; ll ans=0; int main() { n=read(); for(int i=1;i<=n;i++) ans+=n/i; printf("%lld ",ans); return 0; }