Project Euler Homework
|
00001 00009 #include <iostream> 00010 #include "032_permutation.h" 00011 #include "041_prime_table.h" 00012 00013 using namespace std; 00014 00015 unsigned 00016 valueOf (perm032 & perm, unsigned N) 00017 { 00018 unsigned number = 0; 00019 for (idx i = 0; i < N; i++) 00020 number = number * 10 + perm[i]; 00021 return number; 00022 } 00023 00024 int 00025 main () 00026 { 00027 prime_table primes (unsigned (1e9)); 00028 unsigned max = 0; 00029 00030 bool flag = 0; 00031 for (int N = 9; N > 0; N--) 00032 { 00033 perm032 perm (N); 00034 do 00035 { 00036 unsigned number = valueOf (perm, N); 00037 if (number > max && primes.has (number)) 00038 { 00039 max = number; 00040 flag = 1; 00041 } 00042 } 00043 while (perm.next ()); 00044 if (flag) 00045 break; 00046 } 00047 cout << max << endl; 00048 return 0; 00049 }