Created
December 1, 2024 19:13
-
-
Save lychees/c199fb77015d5dec20d659c0bffecb7f to your computer and use it in GitHub Desktop.
https://projecteuler.net/problem=853 有用的素数只有8个,随便搜。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <lastweapon/io> | |
# | |
using namespace lastweapon; | |
const int PMAX = 10000; | |
VI P; bitset<PMAX> isC; | |
#define ii (i*P[j]) | |
void sieve(){ | |
FOR(i, 2, PMAX){ | |
if (!isC[i]) P.PB(i); | |
for (int j=0;j<SZ(P)&&ii<PMAX;++j){ | |
isC[ii]=1; if (!(i%P[j])) break; | |
} | |
} | |
} | |
#undef ii | |
const int N = 121; | |
int f[N]; | |
int a(int n) { | |
f[0] = 0, f[1] = 1 % n; | |
set<PII> S; S.insert({f[0], f[1]}); | |
FOR_1(i, 2, 121) { | |
f[i] = (f[i-1] + f[i-2]) % n; PII p = {f[i-1], f[i]}; | |
if (CTN(S, p)) return i-1; | |
S.insert(p); | |
} | |
return 0; | |
} | |
LL z = 0; | |
void dfs(LL n = 1, int k = 0, int an = 1) { | |
//cout<<n << " " << k << " " << an << endl; | |
if (!an || k >= SZ(P)) { | |
return; | |
} else { | |
int p = P[k++], pp = p, ap = a(p); dfs(n, k, an); | |
if (ap == 0) return; | |
while (ap <= 120) { | |
int t = lcm(an, ap); if (!t || 120 % t) break; | |
if (n*pp>1000000000) break; | |
if (t == 120) { | |
//cout << n*pp << " " << ap << " " << p << endl; | |
z += n*pp; | |
} | |
dfs(n*pp, k, t); pp *= p; ap *= p; | |
} | |
} | |
} | |
int main() { | |
#ifndef ONLINE_JUDGE | |
freopen("in.txt", "r", stdin); | |
//freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout); | |
#endif | |
//REP_1(i, 120) cout << a(i) << endl; | |
sieve(); | |
cout << SZ(P) << endl; | |
VI PP = P; P.clear(); | |
for (auto p: PP) { | |
//if (p>5 && ((p-1)%120) && ((2*p+2)%120)) { | |
//} else { | |
int ap = a(p); | |
if (ap && !(120%ap)) { | |
cout << p << endl; | |
P.PB(p); | |
} | |
} | |
cout << SZ(P) << endl; | |
dfs(); | |
cout << z << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment