P4167 [Violet] cherry

Topic background

He went to the year the cherry blossom season. Vani and sister went to see the cherry blossoms with time, find a big cherry tree, top covered with pink cherry blossoms. Vani bit rough estimate, a total of a full n! Petals.

Vani gently said to her: "You know there's a petal on behalf of you, I randomly pick from the inside one, the probability of energy and you meet only 1 / n so small that how lucky I am, it?!. today let you stand so close to me.

Believe me, I would definitely put this a million millionth of fate changed forever. "

Pink cherry blossoms filled the air, instantly sister Vani moved. She gently hold up his hand, and he sat dependent. Then she suddenly saw the end of the field with two cherry trees and long, then slowly head on Vani's shoulder, whispered in his ear: "See the sunset that two cherry trees yet? which is a tree of your petal, petal on another tree is me, if someone picked from a tree, plucked from a tree, the probability that we will not meet exactly 1 / n! it? "

Vani rapid brain operation a bit, immediately calculate the answer. Was about to tell my sister, she suddenly said softly: "Before, you always say that I am not good at math, but this simple question I'll still be counted if you look at the left of that tree x trailers.

Lobe, right side of the petals have y, then the probability is that we met no 1 / x + 1 / y what, but how many cases can

It just may be equal to 1 / n! It? This you do to help me count it ~ "

Clearly, in the face of a natural stay lovely sister, Vani not only can not Tucao her math slag, but also honestly help her calculate the answer oh.

Title Description

Indefinite equation

1 / x + 1 / y = 1 / n!

Positive integer number of solutions (x, y) of.

Input Format

An integer n.

Output Format

An integer representing the number of (x, y) satisfy the meaning of the questions. The answer to 10 ^ 7 + 9 mod.

Sample input and output

Input # 1
2
Output # 1
3 

Description / Tips

Sample Description

There are three pairs of (x, y) satisfies the condition, namely (3,6) (4,4) and (6,3).

Data for the 30% range with the agreed data guarantee n≤100.

Thinking

There are three pairs of (x, y) satisfies the condition, namely (3,6) (4,4) and (6,3).

To (n!) ^ 2 unique decomposition, the most violent approach is direct decomposition, that is, for every n, enumerate every prime number less than sqrt (n), the time complexity is O (sqrt (n) * )

Code:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1000010;
const int Mod=1e9+7;

int n,ans;
long long fj[N],v[N];
long long p[N],tot=0;

void work(int n) {
	memset(p,0,sizeof(p));
	memset(v,0,sizeof(v));
	tot=0;
	for(int i=2; i<=n; i++) {
		if(!v[i]) {
			v[i]=i;
			tot++;
			p[tot]=i;
		}
		for(int j=1; j<=tot; j++) {
			if(i*p[j]>n||v[i]<p[j])
				break;
			v[p[j]*i]=p[j];
		}
	}
}

int main () {
	scanf("%d",&n);
	work(n);
	for(int i=1; i<=n; i++)
		for(int j=i; j!=1; j/=v[j]) {
			++fj[v[j]];
			fj[v[j]]%=Mod;
		}
	ans=1;
	for(int i=1; i<=n; i++)
		ans=(ans*(fj[i]<<1|1))%Mod;
	printf("%lld\n",ans);
	return 0;
}

 

Guess you like

Origin www.cnblogs.com/mysh/p/11297314.html