Window
Tournament Chart
Prime-Factor Prime
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int l,r;
int prime[32000],tot;
bool vis[32000],prie[32000];
vector<int>a[1000001];
void init() {
for (int i = 2; i <= 31652; i++) {
if (!vis[i]) {
prime[tot++] = i;
prie[i] = 1;
}
for (int j = 0; j < tot && 1ll*prime[j] * i <= 31652; j++) {
vis[prime[j] * i] = 1;
if (i % prime[j] == 0) {
break;
}
}
}
}
int main() {
init();
int ans = 0;
scanf("%d%d", &l, &r);
for (register int i = 0; i < tot; ++i) {
for (register int j = l/prime[i]*prime[i];j<=r; j += prime[i]) {
if (j >= l)
a[j - l].push_back(prime[i]);
}
}
for (register int i = l; i <= r; ++i) {
int x = i;
int cnt = 0, sz = a[i - l].size();
for (register int j = 0; j < sz; ++j) {
while (x % a[i - l][j] == 0) {
cnt++;
x = x / a[i - l][j];
if (x == 1) break;
}
}
if (x>1){
cnt++;
}
if (prie[cnt]) {
ans++;
//printf("%d ",i);
}
}
printf("%d
", ans);
}
Coin Slider
#include <bits/stdc++.h>
using namespace std;
const int maxn=30;
const int maxm=1<<17;
int sx[maxn],sy[maxn],tx[maxn],ty[maxn],n,r[maxn],dp[maxm];
const double eps=1e-5;
struct Point{
int x,y;
Point(){};
Point(int _x,int _y):x(_x),y(_y){};
Point operator-(const Point &a)const {
Point tmp=*this;
tmp.x-=a.x;
tmp.y-=a.y;
return tmp;
}
};
struct Line{
Point s,t;
Line(Point _s,Point _t):s(_s),t(_t){};
};
double xmult(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double distance(Point p1,Point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double disptoline(Point p,Point l1,Point l2)
{
return fabs(xmult(p,l1,l2))/distance(l1,l2);
}
int intersect_seg_circle(Point c,double r, Point l1,Point l2)
{
double t1=distance(c,l1)-r,t2=distance(c,l2)-r;
Point t=c;
if (t1<eps||t2<eps)
return t1>-eps||t2>-eps;
t.x+=l1.y-l2.y;
t.y+=l2.x-l1.x;
return xmult(l1,c,t)*xmult(l2,c,t)<eps&&disptoline(c,l1,l2)-r<eps;
}
double d;
vector<Point>point;
vector<int>R;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d%d%d%d", &r[i], &sx[i], &sy[i], &tx[i], &ty[i]);
dp[0] = 1;
for (int i = 0; i < 1 << n; i++) {
if (dp[i]) {
for (int j = 0; j < n; j++) {
if (((i >> j) & 1) == 0) {
Line L(Point(sx[j], sy[j]), Point(tx[j], ty[j]));
point.clear();
R.clear();
for (int k = 0; k < n; k++) {
if (j != k) {
if ((i >> k) & 1) {
point.push_back(Point(tx[k], ty[k]));
R.push_back(r[k]);
} else {
point.push_back(Point(sx[k], sy[k]));
R.push_back(r[k]);
}
}
}
int f = 1, sz = point.size();
for (int k = 0; k < sz; k++) {
if (intersect_seg_circle(point[k],r[j]+R[k],L.s,L.t)) f = 0;
}
if (f) dp[i + (1 << j)] = 1;
}
}
}
}
int ans = 0;
for (int i = 0; i < 1 << n; i++) {
int k = 0;
if (dp[i]) {
for (int j = 0; j < n; j++) {
if ((i >> j) & 1)
k++;
}
}
ans = max(ans, k);
}
printf("%d
", ans);
}
Conveyor Belt