-
-
Save realmonster/fa760625327db51528bc32c69fc6afad to your computer and use it in GitHub Desktop.
prime tan challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
#include <vector> | |
#include <algorithm> | |
const int MAXT = 1e7; | |
using namespace std; | |
typedef long long ll; | |
double pi = acos(-1.0); | |
double tann(double x) | |
{ | |
return tan(x); | |
} | |
void solve() | |
{ | |
vector<pair<double,int>> tab; | |
for (int i = 0; i < MAXT; ++i) | |
{ | |
tab.push_back(pair<double, int>(fmod((double)i,pi), i)); | |
} | |
sort(tab.begin(), tab.end()); | |
for (double i = 0; i < 9.007e8; ++i) | |
{ | |
double ii = i*MAXT; | |
double r = pi-fmod(ii + pi/2, pi); | |
if (r < 0) | |
r += pi; | |
vector<pair<double,int>>::iterator fi = lower_bound(tab.begin(), tab.end(), pair<double, int>(r, 0)); | |
int f = 0; | |
if (fi != tab.end()) | |
f = fi - tab.begin(); | |
int j = f; | |
int cnt = 0; | |
while (tann(ii+tab[j].second) >= 0) | |
{ | |
j = (j + 1) % MAXT; | |
++cnt; | |
} | |
while (tann(ii+tab[j].second) < 0) | |
{ | |
j = (j + MAXT - 1) % MAXT; | |
++cnt; | |
} | |
//printf("(%lf %lf)\n", r, tab[j].first); | |
for(;;) | |
{ | |
++cnt; | |
pair<double, int> &v = tab[j]; | |
double t = tann(ii + v.second); | |
if (ii+v.second-1e-7 < t) | |
{ | |
printf("%d %lf %d %lf %lf\n", j, v.first, v.second, t, ii+v.second); | |
fflush(stdout); | |
} | |
if (t < ii) | |
break; | |
j = (j + MAXT - 1) % MAXT; | |
} | |
//if (cnt > 20) | |
// printf("===%lf %d\n", ii, cnt); | |
} | |
} | |
int main() | |
{ | |
solve(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment