YBTOJ C. 【例题3】不定方程

在这里插入图片描述
方程移项可得 y = x n ! x − n ! y=\frac{xn!}{x-n!} y=xn!xn! x − n ! = t x-n!=t xn!=t 得到 y = n ! + n ! 2 t y=n!+\frac{n!^2}{t} y=n!+tn!2为题就转换为 n ! 2 n!^2 n!2的约数,所以先算n以内的质数,再计算每个质数出现的次数,即可
公式 ∏ i c n t ( c [ i ] ∗ 2 ) + 1 \prod_{i}^{cnt}(c[i]*2)+1 icnt(c[i]2)+1
注意:记得取余!
Code

#include<bits/stdc++.h>
#define re register

#define inl inline

#define int long long

using namespace std;
int read(){
	int sum=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)){sum=(sum<<3)+(sum<<1)+(c^48);c=getchar();}
	return f*sum;
}
int c[10000010],cnt;
const int mod=1e9+7;
int pri[10000010];
int v[10000010];
inl void init(int n){
	for(re int i=2;i<=n;i++){
		if(!v[i]) v[i]=i,pri[++cnt]=i;
		for(int j=1;j<=cnt;j++){
			if(pri[j]>v[i]||pri[j]>n/i) break;
			v[pri[j]*i]=pri[j];
		}
	}
}
int ans=1;
signed main(){
	int n=read();
	init(n);
	for(re int i=1;i<=cnt;i++){
		for(re int j=pri[i];j<=n;j*=pri[i]){
			c[i]+=n/j;
			c[i]%=mod;
		}
	}
	for(re int i=1;i<=cnt;i++){
		ans=(ans*(c[i]*2+1)%mod+mod)%mod;
	}
	printf("%lld",ans);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值