Hdu 5430 Reflect (geometric basis + mathematics)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.