C. Strange Function-Codeforces Round #729 (Div. 2)

题目链接Problem - 1542C - Codeforces

C. Strange Function

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let f(i)f(i) denote the minimum positive integer xx such that xx is not a divisor of ii.

Compute ∑ni=1f(i)∑i=1nf(i) modulo 109+7109+7. In other words, compute f(1)+f(2)+⋯+f(n)f(1)+f(2)+⋯+f(n) modulo 109+7109+7.

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104), the number of test cases. Then tt cases follow.

The only line of each test case contains a single integer nn (1≤n≤10161≤n≤1016).

Output

For each test case, output a single integer ansans, where ans=∑ni=1f(i)ans=∑i=1nf(i) modulo 109+7109+7.

Example

input

Copy

6
1
2
3
4
10
10000000000000000

output

Copy

2
5
7
10
26
366580019

Note

In the fourth test case n=4n=4, so ans=f(1)+f(2)+f(3)+f(4)ans=f(1)+f(2)+f(3)+f(4).

  • 11 is a divisor of 11 but 22 isn't, so 22 is the minimum positive integer that isn't a divisor of 11. Thus, f(1)=2f(1)=2.
  • 11 and 22 are divisors of 22 but 33 isn't, so 33 is the minimum positive integer that isn't a divisor of 22. Thus, f(2)=3f(2)=3.
  • 11 is a divisor of 33 but 22 isn't, so 22 is the minimum positive integer that isn't a divisor of 33. Thus, f(3)=2f(3)=2.
  • 11 and 22 are divisors of 44 but 33 isn't, so 33 is the minimum positive integer that isn't a divisor of 44. Thus, f(4)=3f(4)=3.

Therefore, ans=f(1)+f(2)+f(3)+f(4)=2+3+2+3=10ans=f(1)+f(2)+f(3)+f(4)=2+3+2+3=10.

----------------------------------------------------------------------------------------------------------------------------

首先,n范围内能整除a,但不能整除b的数,在这里有一个结论

cnt==n/a-n/lcm(a,b)  也就是能整除a的个数减去能整除两者最小公倍数的个数

那么这个题和这一结论有什么关联呢。

首先,f[x]如果等于b ,那么它一定能整除1,2,3,.....b-1,但不能整除b

再转化一下,他能整除1,2,3...b-1的最小公倍数,但不能整除b.

下面是前i个数的最小公倍数,可以发现其实增长是很快的。

这样就可以从1开始枚举前i个数的最小公倍数。比如枚举到前b-1个数的最小公倍数,那么满足条件的n 就是能整除这一最小公倍数但是又不能整除b和这一最小公倍数的最小公倍数的个数 符号化就是 n/lcm-n/lcm(b,lcm) 一共有这么多,但是答案要求求出满足条件的数,所以应该再乘上b即可。

这样做为什么可行,对于一个n来说,1--n之内的f[n]必定是在很小范围内的,我们枚举每个可能,找到个数,限定b-1的范围在n之内,就可以把全部情况都找出。为什么要b-1限定在n之内?因为b还可以大于n,比如f[1]=2。b-1限定在n之内就枚举了全部能整除的情况,毫无遗漏。

# include<iostream>
# include<algorithm>
# include<iomanip>

using namespace std;
typedef long long int ll;

ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;

}
ll mod=1e9+7;

int main()
{

     int t;
     cin>>t;

     while(t--)
     {
         ll n;
         cin>>n;


         ll ans=0;
         ll pre=1;
         ll now=2;

         while(pre<=n)
         {
             ans+=now*((n/pre)-n/lcm(pre,now));
             ans%=mod;


             pre=lcm(pre,now);
             now++;
         }

         cout<<ans%mod<<'\n';

     }
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秦三码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值