码迷,mamicode.com
首页 > 其他好文 > 详细

Luogu1445 [Violet]樱花

时间:2018-12-27 18:26:17      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:type   inline   def   str   git   amp   ems   freopen   lin   

题面

题解

$$ \frac 1x + \frac 1y = \frac 1{n!} \\ \frac{x+y}{xy}=\frac 1{n!} \\ xy=n!(x+y) \\ xy-n!(x+y)=0 \\ (x-n!)(y-n!)=(n!)^2 \\ $$

因为确定$(x-n!),(y-n!)$就能确定$x,y$,所以答案就是$d((n!)^2)$

代码

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x))

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while(ch != ‘-‘ && (!isdigit(ch))) ch = getchar();
	if(ch == ‘-‘) w = -1, ch = getchar();
	while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int maxn(10000010), Mod(1e9 + 7);
int n, prime[maxn], cnt;
long long c[maxn];
bool not_prime[maxn];

void init()
{
	not_prime[1] = true;
	for(RG int i = 2; i <= n; i++)
	{
		if(!not_prime[i]) prime[++cnt] = i;
		for(RG int j = 1; j <= cnt && i * prime[j] <= n; j++)
		{
			not_prime[i * prime[j]] = true;
			if(!(i % prime[j])) break;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read(); init();
	for(RG int i = 1; i <= cnt; i++)
	{
		int p = prime[i];
		for(RG long long j = p; j <= n; j *= p) c[i] += (n / j);
		c[i] %= Mod;
	}
	long long ans = 1;
	for(RG int i = 1; i <= cnt; i++) ans = ans * (c[i] << 1 | 1) % Mod;
	printf("%lld\n", ans);
	return 0;
}

Luogu1445 [Violet]樱花

标签:type   inline   def   str   git   amp   ems   freopen   lin   

原文地址:https://www.cnblogs.com/cj-xxz/p/10185337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!