Reflect

 Accepts: 72
 Submissions: 302
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
从镜面材质的圆上一点发出一道光线反射NN次后首次回到起点。
问本质不同的发射的方案数。
输入描述
第一行一个整数T,表示数据组数。T \leq 10T≤10
对于每一个组,共一行,包含一个整数,表示正整数N(1 \leq N \leq 10^{6})N(1≤N≤10​6​​)。
输出描述
对于每一个组,输出共一行,包含一个整数,表示答案。
输入样例
1
4
输出样例
4

如果k/(N+1)不是既约分数的话,即可以约分,说明该方案之前出现过,这次只不过所有的线跑了两遍,不符合题目中“首次”回到起点的含义。所以就是求有多少个k符合条件。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int euler(int n)
{
int res = n, a = n;
for (int i = 2; i*i <= a; i++)
{
if (a%i == 0)
{
res = res / i*(i - 1);
while (a%i == 0)a /= i;
}
}
if (a > 1)res = res / a*(a - 1);
return res;
} int main()
{
int test;
cin >> test;
int n;
while (test--)
{
cin >> n;
cout << euler(n+1) << endl;
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5430:Reflect 欧拉函数的更多相关文章

  1. Reflect(欧拉函数)

    Reflect Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  2. HDU 2824 简单欧拉函数

    1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...

  3. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. HDU 2588 GCD (欧拉函数)

    GCD Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  5. HDU 1695 GCD 欧拉函数+容斥定理

    输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...

  6. hdu 6434 Count (欧拉函数)

    题目链接 Problem Description Multiple query, for each n, you need to get $$$$$$ \sum_{i=1}^{n} \sum_{j=1 ...

  7. HDU 1695 GCD (欧拉函数,容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. hdu 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. Problem I. Count - HDU - 6434(欧拉函数)

    题意 给一个\(n\),计算 \[\sum_{i=1}^{n}\sum_{j=1}^{i-1}[gcd(i + j, i - j) = 1]\] 题解 令\(a = i - j\) 要求 \[\sum ...

  10. HDU 3501【欧拉函数拓展】

    欧拉函数 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) . 通式:φ(x)=x*(1-1/p1)(1-1/p2)(1-1/p3)*(1-1/p4)-..(1- ...

随机推荐

  1. 使用IDEA,Eclispe搭建Spring Boot项目

    如何创建一个Spring Boot项目?这里使用maven来进行依赖管理,根据常用的IDE,可以使用IDEA.Eclipse.或者访问官方网站搭建. 项目搭建环境准备 JDK:1.8 MAVEN:3. ...

  2. js 用于运行string中的<script>和</script>之间的函数

    /** * Created by 炜文 on 2017/2/15. */ var intext = '485222<script> var i=2;var j=2;console.log( ...

  3. 基于zedboard的DMA设计笔记

    2.BAR0空间的概念:BAR(Base Address Register ) 该组寄存器简称为BAR寄存器,BAR寄存器保存PCI设备使用的地址空间的基地址,该基地址保存的是该设备在PCI总线域中的 ...

  4. 项目启动异常,java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...

  5. 必应壁纸php获取接口

    <?php if($_GET['idx']==null){ $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx= ...

  6. SciPy 插值

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  7. Typora: Markdown Reference (Typora下Markdown语法使用说明)

    引言 由于一直在使用Typora,这个是我使用过的最棒的Markdown编辑器,但是总是忽略某一个功能,于是决定认真看一下其帮助文档 这里做一个简单主要功能的中文翻译(按键对应Windows下). 标 ...

  8. 【pwnable.tw】 seethefile

    一开始特别懵的一道题. main函数中一共4个功能,openfile.readfile.writefile.closefile. 其中,在最后退出时有一个明显的溢出,是scanf("%s&q ...

  9. oracle的存储过程和函数有什么区别?

    Oracle中的函数与存储过程的区别:      A:函数必须有返回值,而过程没有. B:函数可以单独执行.而过程必须通过execute执行. C:函数可以嵌入到SQL语句中执行.而过程不行. 其实我 ...

  10. Unable to execute dex:Multuple dex files define 解决方法

    困扰我两天的问题终于解决了,在网上查的方法无非有三种 一. Eclipse->Project->去掉Build Automatically->Clear ->Build Pro ...