Project Euler problem 47
2012-11-06 14:04
246 查看
还是暴力
我先试着把15W个数进行素因子分解
然后4个的存起来
然后搜一下
发现还真的在15W以内
我先试着把15W个数进行素因子分解
然后4个的存起来
然后搜一下
发现还真的在15W以内
#include <iostream> #include <cstdio> #include <cstring> #include <ctime> #include <cstdlib> #include <algorithm> #include <stack> #include <cmath> #include <vector> #define eps 1e-6 #define INF 1000000007 #define PI acos(-1.0) using namespace std; vector<int>g; bool tag[4001]; int p[4001]; int cnt; void get_prime() //筛出5000000内素数 { cnt = 0; tag[1] = 1; for (int i = 2; i < 4000; i++) { if (!tag[i]) p[cnt++] = i; for (int j = 0; j < cnt && p[j] * i < 4000; j++) { tag[i*p[j]] = 1; if (i % p[j] == 0) break; } } } void gao(int x) { int tx = x; int ans = 0; for(int i = 0; i < cnt && p[i] * p[i] <= x; i++) { if(x % p[i] == 0) { while(x % p[i] == 0) x /= p[i]; ans++; } } if(x != 1) ans++; if(ans == 4) g.push_back(tx); } int main() { get_prime(); for(int i = 10; i <= 150000; i++) gao(i); for(int i = 0; i < g.size(); i++) if(i + 3 < g.size() && g[i] + 1 == g[i + 1] && g[i + 1] + 1 == g[i + 2] && g[i + 2] + 1 == g[i + 3]) { cout << g[i] << endl; break; } return 0; }
相关文章推荐
- Project Euler Problem 47 Distinct primes factors
- Project Euler Problem 47
- project euler Problem 25
- http://projecteuler.net/problem=8 [Answer:40824]
- http://projecteuler.net/problem=17 [Answer:21124]
- Project Euler -> problem 5
- Project Euler problem 63
- project euler problem 12
- Project Euler Problem 15 Lattice paths
- project euler problem 30
- Project Euler Problem 59
- Project Euler problem 22
- Project Euler Problem 1
- Project Euler Problem 21
- projecteuler Problem 29
- Project Euler Problem 30
- Project Euler Problem 81-90
- project euler Problem 52
- http://projecteuler.net/problem=18 [Answer:1074]
- http://projecteuler.net/problem=32 [Answer:45228]