https://ac.nowcoder.com/acm/problem/14682——约数的个数(计算贡献)
约数个数的和
https://ac.nowcoder.com/acm/problem/14682
题目链接:https://ac.nowcoder.com/acm/problem/14682
思路:计算n以内每个数的贡献次数求和即可。
代码:
//#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<map> #include<vector> #include<set> #include<utility> #include<algorithm> using namespace std; typedef long long LL; const int maxn=1e5+5; const int N=1e8+5; const LL mod=1e9+7; int read() { char ch=getchar();int x=0,f=1; 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 gcd_(int a,int b) {return b==0?a:gcd_(b,a%b);} LL fpow(LL a,LL b) { LL res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); // cout<<"Accepted!\n"; int n; cin>>n; LL sum=0; for(int i=1;i<=n;++i) { sum+=n/i; } cout<<sum; return 0; }