https://codeforces.com/contest/1542/problem/C
一些规则如下:
Some rules are as follows:
1 1到n中,a的倍数有n/a个
2 如果一个数是1,2,3,4,5,…,k的倍数,那么这个数是1,2,…,k的最小公倍数
3 如果一个数是1,2,3,…,k的最小公倍数的倍数,并且不是1,2,3,…,k+1的最小公倍数的倍数,那么这个数的函数值为k+1
4
1 From 1 to N, there are n / a multiples of A
2 If a number is a multiple of 1,2,3,4,5,…, K, then the number is the least common multiple of 1,2,…, K
3 If a number is a multiple of the least common multiple of 1,2,3,…, K, and is not a multiple of the least common multiple of 1,2,3,…, K + 1, then the function value of the number is K + 1
因此,我只需保证1到n中每个数,若为1的lcm的倍数,加一,若为1到2的lcm的倍数,再加一,若为1到3的lcm的倍数,再加一,依次下去。另外在最后每个数再加一即可。
So I just need to make sure that every number from 1 to N, if it’s a multiple of LCM of 1, add one, if it’s a multiple of LCM of 1 to 2, add one, if it’s a multiple of LCM of 1 to 3, add one, and so on. In addition, add one to each last number.
代码
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t, n, lc[200], mod = 1e9 + 7;
void getlcm()
{
lc[0] = 1;
for(ll u = 1; lc[u - 1] <= 1e16; u ++) lc[u] = lcm(lc[u - 1], u);
}
int main()
{
getlcm();
cin >> t;
while(t --)
{
cin >> n;
ll res = n % mod;
for(ll i = 1; lc[i]; i ++) (res += n / lc[i]) %= mod;
cout << res << endl;
}
}