Mancala II


A Rational Sequence


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p,q,a;
int main()
{
int _,k;
scanf("%d",&_);
while (_--)
{
scanf("%d %lld/%lld",&k,&q,&p);
printf("%d ",k);
if (p==1&q==1)
{
printf("1/2
");
continue;
}
if (p==1)
{
printf("1/%lld
",q+1);
continue;
}
if (q==1)
{
printf("%lld/%lld
",p,p-q);
continue;
}
if (p==2)
{
printf("%lld/%lld
",p,q);
continue;
}
if (q<p)
{
printf("%lld/%lld
",p,p-q);
continue;
}
a=0;
a=q/p;
q=q%p;
// while (p<=q)
// {
// q-=p;
// a++;
// }
printf("%lld/%lld
",p,p-q+a*p);
}
return 0;
}
Growing Rectangular Spiral


#include <bits/stdc++.h>
using namespace std;
int T;
int main()
{
cin>>T;
while(T--)
{
int k;
scanf("%d",&k);
int a,b;
scanf("%d %d",&a,&b);
if(a<b)
{
printf("%d 2 ",k);
printf("%d %d
",a,b);
}
else if(b<4)
{
printf("%d NO PATH
",k);
}
else
{
printf("%d 6 1 2 3 ",k);
printf("%d %d %d
",a-b+5,a+2,a+3);
}
}
return 0;
}
Farey Sums

#include <bits/stdc++.h>
using namespace std;
const int N=100100;
typedef long long ll;
int phi[N+10],prime[N],vis[N+10],tot;
void get_euler()
{
phi[1]=1;
for (int i=2; i<=N; i++)
{
if (!vis[i])
{
prime[tot++]=i;
phi[i]=i-1;
}
for (int j=0; j<tot&&1ll*prime[j]*i<=N; j++)
{
vis[prime[j]*i]=1;
if (i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
phi[i*prime[j]]=phi[i]*phi[prime[j]];
}
}
}
int main()
{
get_euler();
int _,n,k;
ll sum;
scanf("%d",&_);
while (_--)
{
sum=0;
scanf("%d%d",&k,&n);
printf("%d ",k);
for (int i=1;i<=n;i++){
sum+=phi[i];
}
printf("%lld/2
",sum*3-1);
}
}
The Queen’s Super-circular Patio


#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
double r[1000],d,a,b,c,x,A;
int main()
{
int _,k,n,m;
scanf("%d",&_);
while (_--)
{
scanf("%d%d%d",&k,&n,&m);
printf("%d ",k);
d=pi/n;
r[1]=1;
r[2]=sin(d)/(1-sin(d));
A=r[1]+r[2];
a=tan(d);
a=1/(a*a);
c=A*A-r[2]*r[2];
b=-2*r[2]-2*A/tan(d);
r[3]=(-b+sqrt(b*b-4*a*c))/(2*a);
for (int i=4; i<=m+1; i++)
{
r[i]=(r[i-1]*r[i-1])/r[i-2];
}
printf("%.3f %.3f
",r[m+1],r[m+1]*2*n+2*pi*r[m+1]);
}
}