Codeforces Round #729 (Div. 2) c题

https://codeforces.com/contest/1542/problem/C


题目大意

定义 f ( i ) f(i) f(i) 为不能整除 i i i 的正整数, 例如 f ( 1 ) = 2 f(1) = 2 f(1)=2 f ( 2 ) = 3 f(2) = 3 f(2)=3,求 f ( 1 ) + f ( 2 ) + . . . + f ( n ) f(1)+f(2)+...+f(n) f(1)+f(2)+...+f(n)


题解

先求 1 1 1 i − 1 i-1 i1 的最小公倍数,最大数不超过 1 e 16 1e^{16} 1e16

ans = 2 * n % mod;
ans=(ans+n/pre[i]);


代码

#include<bits/stdc++.h>
using namespace std;
#define re register int
#define int long long
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f==1?x:-x;
}
const int maxn=1e16+10,modp=1e9+7;
int gcd(int x,int y)
{
	return !y?x:gcd(y,x%y);
}
int Lcm[50]; 
signed main()
{
	int tmp=1,x=1;
	while(1)
	{
		Lcm[tmp]=x;
		x=x*tmp/gcd(x,tmp);
		if(x>maxn)break;
		tmp++;
	}
	//cout << tmp<<endl;
    //for(re i=1;i<=tmp;++i)cout<<Lcm[i]<<" ";
	int T=read();
	while(T--)
	{
		int n=read(),ans=2*n%modp;
		for(re i=3;i<=tmp;++i)
			ans=(ans+n/Lcm[i])%modp;
		printf("%lld\n",ans);
	}
	return 0;
}

大佬的代码搬过来了,侵删!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值