Test instructions: Emitting a ray from a circle at a point after N times reflection back to the starting point, the number of solutions;
Idea: The emission Ray and its in the point tangent line of the angle is recorded as Sita, then each edge corresponding to the center of the angle of 2*sita, reflection n times have n+1 edge, then 2*sita* (n+1) =2*k*pi,k is an integer;
sita=pi*k/(n+1); The number of Sita is the same as that of K and (n+1) coprime, so it is converted to the number of cases of K and n+1 coprime;
can be solved by Euler function or Rho algorithm;
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intt,n,m;intgcdintAintb) { if(b==0)returnA; returnGCD (b,a%b);}intMain () {intI,j,k,ans; scanf ("%d",&t); while(t--) {scanf ("%d",&N); Ans=0; for(i=1; i<=n+1; i++){ if(GCD (i,n+1)==1) {ans++; }} printf ("%d\n", ans); } return 0;}
Hdu 5430 Reflect (geometric basis + mathematics)