ural 1860

求f[i]的不同因子数。f[i] = i * f[i - 1] * f[i - 2],f[1] = 1, f[0] = 1

类似斐波拉契数要想到斐波拉契数列。

f[2] = 2

f[3] = 2 * 3

f[4] = 2 * 2 * 3 * 4

f[5] = 2 * 2 * 2 * 3 * 3 * 4 * 5

所以f[i]中k的个数和斐波拉契数有关。个数为fi[n - k],因为n的个数1,n - 1个数为fi[1],n - 2个数为fi[2] = 2....

求不同因子数,要把所以质因子找出来,把f[i]中所有因子的质因子找出来即可。

#include <cstdio>
#include <string.h>
#include <cmath>

const int MAX_NUMBER = 1000001;
const long long MOD_NUMBER = 1000 * 1000 * 1000 + 7;

bool vis[MAX_NUMBER + 1];
long long ans[MAX_NUMBER];
long long fi[MAX_NUMBER];
int prime[MAX_NUMBER];
int prime_number;

int main() {
	fi[0] = 1;
	fi[1] = 1;
	for (int i = 2; i < MAX_NUMBER; i++) {
		fi[i] = (fi[i - 1] + fi[i - 2]) % MOD_NUMBER;
	}
	int number;
	memset(vis, 0, sizeof(vis));
	memset(ans, 0, sizeof(ans));
	scanf("%d", &number);
	for (long long i = 2; i <= number; i++) {
		if (!vis[i]) {
			ans[i] = fi[number - i];
			long long j = i + i;
			while (j <= number) {
				vis[j] = 1;
				long long temp = j;
				while (temp % i == 0) {
					ans[i] = (ans[i] + fi[number - j]) % MOD_NUMBER;
					temp /= i;
				}
				j += i;
			}
		}
	}
	long long result = 1;
	for (int i = 2; i <= number; i++) {
		if (!vis[i]) {
			result = (result * (ans[i] + 1)) % MOD_NUMBER;
		}
	}
	printf("%I64d\n", result);
	return 0;
}


你可能感兴趣的:(ural 1860)