Skip to content

Instantly share code, notes, and snippets.

@lychees
Created July 11, 2020 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lychees/aaa1d201cae9d15b1c31f5619f75d8c9 to your computer and use it in GitHub Desktop.
Save lychees/aaa1d201cae9d15b1c31f5619f75d8c9 to your computer and use it in GitHub Desktop.
Go
/* &*#()&*#)&E*F& */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define REP(I, N) for (int I=0;I<int(N);++I)
#define FOR(I, A, B) for (int I=int(A);I<int(B);++I)
#define DWN(I, B, A) for (int I=int(B-1);I>=int(A);--I)
#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define ALL(A) A.begin(), A.end()
#define CLR(A) A.clear()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define SRT(A) sort(ALL(A))
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
typedef long long LL;
typedef double DB;
template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T> inline void checkMin(T &a, T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a, T b){if (b>a) a=b;}
/* -&$&#*( &#*@)^$@&*)*/
const int MOD = 1000000007;
const int INF = 0x7fffffff;
const int N = 50;
const int PMAX = 10000000;
vector<int> P, PP; 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
// 586081
set<string> S;
class PrimeSubstrings {
public:
string construct(int N, int L) {
P.clear(); PP.clear(); isC.reset();
sieve();
int l = 1, r = 10;
for (int i=2;i<=L;++i) {
l *= 10; r *= 10;
}
--r;
cout << l << " " << r << endl;
ECH(it, P) {
if (l <= *it && *it <= r) {
// cout << " " << *it << endl;
// PP.PB(*it);
int x = *it;
string s;
while (x) {
s.PB(x%10);
x /=10;
}
reverse(s.begin(), s.end());
string ss;
for (int i=1;i<)
x = *it;
s.clear();
while (x) {
s.PB(x%10);
S.PB(s);
x /=10;
}
}
}
cout << PP.size() << endl;
return "0";
}
};
// BEGIN CUT HERE
namespace moj_harness {
int run_test_case(int);
void run_test(int casenum = -1, bool quiet = false) {
if (casenum != -1) {
if (run_test_case(casenum) == -1 && !quiet) {
cerr << "Illegal input! Test case " << casenum << " does not exist." << endl;
}
return;
}
int correct = 0, total = 0;
for (int i=0;; ++i) {
int x = run_test_case(i);
if (x == -1) {
if (i >= 100) break;
continue;
}
correct += x;
++total;
}
if (total == 0) {
cerr << "No test cases run." << endl;
} else if (correct < total) {
cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << endl;
} else {
cerr << "All " << total << " tests passed!" << endl;
}
}
int verify_case(int casenum, const string &expected, const string &received, clock_t elapsed) {
cerr << "Example " << casenum << "... ";
string verdict;
vector<string> info;
char buf[100];
if (elapsed > CLOCKS_PER_SEC / 200) {
sprintf(buf, "time %.2fs", elapsed * (1.0/CLOCKS_PER_SEC));
info.push_back(buf);
}
if (expected == received) {
verdict = "PASSED";
} else {
verdict = "FAILED";
}
cerr << verdict;
if (!info.empty()) {
cerr << " (";
for (int i=0; i<(int)info.size(); ++i) {
if (i > 0) cerr << ", ";
cerr << info[i];
}
cerr << ")";
}
cerr << endl;
if (verdict == "FAILED") {
cerr << " Expected: \"" << expected << "\"" << endl;
cerr << " Received: \"" << received << "\"" << endl;
}
return verdict == "PASSED";
}
int run_test_case(int casenum) {
switch (casenum) {
case 0: {
int N = 4;
int L = 2;
string expected__ = "5317";
clock_t start__ = clock();
string received__ = PrimeSubstrings().construct(N, L);
return verify_case(casenum, expected__, received__, clock()-start__);
}
case 1: {
int N = 7;
int L = 7;
string expected__ = "1301779";
clock_t start__ = clock();
string received__ = PrimeSubstrings().construct(N, L);
return verify_case(casenum, expected__, received__, clock()-start__);
}
case 2: {
int N = 5;
int L = 4;
string expected__ = "13079";
clock_t start__ = clock();
string received__ = PrimeSubstrings().construct(N, L);
return verify_case(casenum, expected__, received__, clock()-start__);
}
// custom cases
/* case 3: {
int N = ;
int L = ;
string expected__ = ;
clock_t start__ = clock();
string received__ = PrimeSubstrings().construct(N, L);
return verify_case(casenum, expected__, received__, clock()-start__);
}*/
/* case 4: {
int N = ;
int L = ;
string expected__ = ;
clock_t start__ = clock();
string received__ = PrimeSubstrings().construct(N, L);
return verify_case(casenum, expected__, received__, clock()-start__);
}*/
/* case 5: {
int N = ;
int L = ;
string expected__ = ;
clock_t start__ = clock();
string received__ = PrimeSubstrings().construct(N, L);
return verify_case(casenum, expected__, received__, clock()-start__);
}*/
default:
return -1;
}
}
}
int main(int argc, char *argv[]) {
if (argc == 1) {
moj_harness::run_test();
} else {
for (int i=1; i<argc; ++i)
moj_harness::run_test(atoi(argv[i]));
}
}
// END CUT HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment