@root

Kinghero King of the summit 2023-08-24 10:01:21 26
这哪错了~~~~~~~~~~~~~~~~~~(只有90分)
#include <bits/stdc++.h>
using namespace std;
long int f[51], mod = 2147483648, m;
int n, i, flag = 0;
int main() {
	f[1] = 1;
	f[2] = 1;
	cin >> n;
	for (i = 3; i <= n; i++) f[i] = f[i - 1] + f[i - 2];
	m = f[n] % mod;
	cout << m << "=";
	i = 2;
	while (m > 1) {
		if (m % i == 0) {
			if (flag == 0) {
				flag = 1;
				cout << i;
				m = m / i;
			} else cout << "*" << i, m = m / i;
		} else i++;
	}
	return 0;
}
{{ vote && vote.total.up }}

共 6 条回复

wc097

先判断一下f[n]是不是质数,是的话会加到超时,所以是质数直接输出自己然后结束

wc097
korme

有一个in是43,直接打表

wyh15 Minecraft
#include <bits/stdc++.h>
using namespace std;
long long int f[51], mod = 2147483648, m;
int n, i, flag = 0;
int main() {
	f[1] = 1;
	f[2] = 1;
	cin >> n;
	for (i = 3; i <= 4; i++){f[i] = (f[i - 1] + f[i - 2]) % mod;}
	m = f[n] % mod;
	cout << m << "=";
	i = 2;
	while (m > 1) {
		if (m % i == 0) {
			if (flag == 0) {
				flag = 1;
				cout << i;
				m = m / i;
			} else cout << "*" << i, m = m / i;
		} else i++;
	}
	return 0;
}
yehongchen
#include <bits/stdc++.h>
using namespace std;
long int f[51], mod = 2147483648, m;
int n, i, flag = 0;
int main() {
    f[1] = 1;
    f[2] = 1;
    cin >> n;
    for (i = 3; i <= n; i++) f[i] = f[i - 1] + f[i - 2] % mod;
    m = f[n] % mod;
    cout << m << "=";
    i = 2;
    while (m > 1) {
        if (m % i == 0) {
            if (flag == 0) {
                flag = 1;
                cout << i;
                m = m / i;
            } else
                cout << "*" << i, m = m / i;
        } else
            i++;
    }
    return 0;
}

???还是有错

root 站长

long long int,然后就是每计算一个 f[i] 就求余一次 f[i] = (f[i - 1] + f[i - 2]) % mod;