/* ID: rodrigo7 PROG: prime3 LANG: C++ */ #include #include #include #include #include #include #include #include using namespace std; template ostream& operator<< (ostream &out, const vector > &v) { typedef ostream_iterator > Iter; copy (v.begin(), v.end(), Iter (out, " ")); return out; } ifstream fin ("prime3.in"); #ifdef USACOLOCAL #define fout cout #else ofstream fout ("prime3.out"); #define cout fout #endif int sum; int topleft; int square[5][5]; bool none_so_far = true; int nprimes = 0; int primes[10000]; char pdigs[10000][5]; bool isprime[100000]; bool first[5][10000]; bool last [5][10000]; bool efirst[5][10000]; bool elast [5][10000]; char givenlen[4][1000]; char given[4][1000][10]; int digsum(int); int col(int c, int len) { int ans = 0; for (int i=0; i=0; i--) ans = ans * 10 + square[i][4-i]; return ans; } void search(int row, int cs[], int d1, int d2) { #if 0 for (int r=0; r<5; r++) { cout << string (row, ' '); for (int c=0; c<5; c++) cout << square[r][c]; cout << endl; } for (int i=0;i<5;i++) cout << cs[i] << " "; cout << d1 << " " << d2 << endl; #endif /* pruning */ if (row == 1) { if (square[0][0] != topleft) return; } /* termination checking */ if (row == 5) { /* woohoo */ if (!none_so_far) fout << endl; none_so_far = false; for (int r=0; r<5; r++) { for (int c=0; c<5; c++) fout << square[r][c]; fout << endl; } return; } int new_cs[5]; int d2mult=1; for (int i=0; i