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>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long

using namespace std;

int eular(int n)
{
    int ret = 1;
    for(int i = 2; i * i <= n; i++)
    {
        if(n % i == 0)
        {
            n /= i;
            ret *= i - 1;
            while(n % i == 0)
            {
                n /= i;
                ret *= i;
            }
        }
    }
    if(n > 1)
        ret *= n - 1;
    return ret;
}
int main()
{
    int T;
    while(~scanf("%d", &T))
    {
        while(T--)
        {
            int n;
            scanf("%d", &n);
            printf("%d\n", eular(n + 1));
        }
    }
    return 0;
}

  

时间: 2024-08-25 03:40:05

HDU 5430 Reflect的相关文章

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次反射回到起点,求方案数: 思路:发射射线与其在该点相切的线的夹角记作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<algorit

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 3586 树状dp

Information Disturbing Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 618 Problem Description In the battlefield , an effective way to defeat enemies is to brea

HDU 5835 Danganronpa(弹丸论破)

HDU 5835 Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of

hdu5430 Reflect

欧拉函数:Φ(n)= n * ∏(1 - 1/pi), 其中pi是n的素因子. 表示不超过n且与n互质的正整数的数目,由容斥原理易证. http://acm.hdu.edu.cn/showproblem.php?pid=5430 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 6 using namespace std; 7 8 cons

HDU 3586.Information Disturbing 树形dp

Information Disturbing Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 3205    Accepted Submission(s): 1137 Problem Description In the battlefield , an effective way to defeat enemies is to bre

HDU - 1430 - 魔板( 康托展开 + BFS预处理 )

魔板 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4242    Accepted Submission(s): 1011 Problem Description 在魔方风靡全球之后不久,Rubik先生发明了它的简化版--魔板.魔板由8个同样大小的方块组成,每个方块颜色均不相同,可用数字1-8分别表示.任一时刻魔板的状态可用方块的颜

Hdu Information Disturbing

Hdu Information Disturbing Description In the battlefield , an effective way to defeat enemies is to break their communication system. The information department told you that there are n enemy soldiers and their network which have n-1 communication