hdu 5430 Reflect(几何基础+数学)

题意:从圆上一点发出射线经过n次反射回到起点,求方案数;

思路:发射射线与其在该点相切的线的夹角记作sita,则每条边所对应的圆心角为2*sita,反射n次有n+1条边,则2*sita*(n+1)=2*k*pi,k为整数;

sita=pi*k/(n+1);sita的种类数与k与(n+1)互质的情况数相同,所以转化为求k与n+1互质的情况数;

可以用欧拉函数或rho算法求解;

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t,n,m;
int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(){
  int i,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;
}
时间: 2024-12-17 05:14:18

hdu 5430 Reflect(几何基础+数学)的相关文章

hdu 5430 Reflect (数学推导题)

Problem Description We send a light from one point on a mirror material circle,it reflects N times and return the original point firstly.Your task is calcuate the number of schemes. ![](../../data/images/C628-1004-1.jpg) Input First line contains a s

HDU 5430 Reflect(欧拉函数)

题目: http://acm.hdu.edu.cn/showproblem.php?pid=5430 从镜面材质的圆上一点发出一道光线反射NNN次后首次回到起点. 问本质不同的发射的方案数. 输入描述 第一行一个整数T,表示数据组数.T≤10T \leq 10T≤10 对于每一个组,共一行,包含一个整数,表示正整数N(1≤N≤106)N(1 \leq N \leq 10^{6})N(1≤N≤10?6??). 输出描述 对于每一个组,输出共一行,包含一个整数,表示答案. 输入样例 1 4 输出样例

HDU 5430 Reflect

题意:问在一个圆形的镜面里,从任意一点发出一个光源,经n次反射回到起点的情况数是多少. 解法:直接贴题解吧…… 求1至N+1中与N+1互质的个数,即欧拉函数. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<limits.h>

HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys

HDU 4937 Lucky Number (数学,进制转换)

题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last); //把[first0,last0)之间的部分替换成[first,last)之间的字符串 /* 题意: 我们将3,4,5,6认为是幸运数字.给定一个十进制数n. 现在可以讲起任意转

HDU 1018 Big Number 数学题解

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of

hdu 4823 Energy Conversion(数学)

题目链接:hdu 4823 Energy Conversion 题目大意:中文题,不解释. 解题思路:首先判断一下m是否已经大于n了,如果大于那么就是0,假设中间变换的各个值为ai,那么bi=ai+c,bi数组为等比数组(可推),所以就有了cnt=log((n+c)a)log(double(k)),结果为浮点数,需要向上取整. #include <cstdio> #include <cstring> #include <cmath> int main () { int

hdu 4710 Balls Rearrangement (数学思维)

题意:就是  把编号从0-n的小球对应放进i%a编号的盒子里,然后又买了新盒子, 现在总共有b个盒子,Bob想把球装进i%b编号的盒子里.求重置的最小花费. 每次移动的花费为y - x ,即移动前后盒子编号的差值的绝对值. 算法: 题目就是要求                  先判断  n与  lcm(a,b)的大小,每一个周期存在循环,这样把区间缩短避免重复计算. 如果n>lcm(a,b)则   ans = (n/lcm)*solve(lcm)+solve(n%lcm) 否则   ans =

HDU 1005 Number Sequence (数学规律)

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104190    Accepted Submission(s): 25232 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A