# public 123Phil /Truncated-Primes

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Fetching contributors…

Cannot retrieve contributors at this time

file 79 lines (59 sloc) 1.09 kb
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 `#include #include using namespace std;#define MAX 1000000bool catPrime(int n, vector& primes);bool isPrime(int n);void Truncate(int &n);int main(){ vector primes; int primer; int numElems = 0; primes.push_back(3); primes.push_back(7); for (primer = 13; primer < MAX; primer++) { if(catPrime(primer, primes)) primes.push_back(primer); } numElems = primes.size(); int i; for(i = 0; i < numElems; i++) cout << primes[i] << endl; return 0;}bool isPrime(int n){ if (n < 2) return false; int i; for(i = 2; i*i <= n; i++) if (n%i == 0) return false; return true;}bool catPrime(int n, vector& primes){ if (!isPrime(n)) return false; Truncate(n); int i; int numElems = primes.size(); for (i = 0; i < numElems; i++) if (n == primes[i]) return true; return false;}void Truncate(int &n){ int i = 0; int dup = n; while (dup >= 10) { dup /= 10; i++; } while (i > 0) { dup *= 10; i--; } n -= dup;}`
Something went wrong with that request. Please try again.