Skip to content

Instantly share code, notes, and snippets.

@realmonster
Created August 21, 2020 15:35
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 realmonster/fa760625327db51528bc32c69fc6afad to your computer and use it in GitHub Desktop.
Save realmonster/fa760625327db51528bc32c69fc6afad to your computer and use it in GitHub Desktop.
prime tan challenge
#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