Skip to content

Instantly share code, notes, and snippets.

@TimDumol
Created November 9, 2012 14:21
Show Gist options
  • Select an option

  • Save TimDumol/4045952 to your computer and use it in GitHub Desktop.

Select an option

Save TimDumol/4045952 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <functional>
#include <utility>
#include <vector>
#include <list>
#include <numeric>
#include <bitset>
using namespace std;
typedef unsigned long long ullong;
typedef long long llong;
typedef list<int> EdgeList;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define FOR_EDGE(adj,v,it) for (EdgeList::iterator it = adj[v].begin(); \
it != adj[v].end(); ++it)
const int sz = 10000;
bitset<sz/2> pbits;
vector<int> primes;
void setup();
int main() {
setvbuf(stdin, NULL, _IOFBF, 10000);
setvbuf(stdout, NULL, _IOFBF, 10000);
//setup();
int sols[1000000];
memset(sols, 0, sizeof(sols));
bool done = false;
for (llong a0 = 1; !done ; ++a0) {
// 2*a0*k + 3k^2 > a0^2
double b = 2*a0;
double a = 3;
double c = -a0*a0;
double start = max(ceil((-b + sqrt(b*b - 4*a*c))/(2*a)), 1.0);
for (llong k = start; ; ++k) {
llong n = a0*(-a0 + 2*k) + 3*k*k;
if (n >= 1000000) {
if (k == start) done = true;
break;
}
++sols[n];
}
}
int cnt = 0;
for (int i = 1; i <= 999999; ++i) {
if (sols[i] == 10) {
printf("%d\n", i);
++cnt;
}
}
printf("%d\n", cnt);
return 0;
}
void setup() {
pbits.set();
const int cap = sqrt(sz) + 1;
for (int i = 3; i < cap; i += 2) {
if (pbits[i/2]) {
for (int j = i*i/2; j < sz/2; j += i) {
pbits.reset(j);
}
}
}
primes.push_back(2);
for (int i = 1; i < sz/2; ++i) {
if (pbits[i]) primes.push_back(2*i+1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment