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. Python可视化 | Seaborn包—kdeplot和distplot

    import pandas as pd import numpy as np import seaborn as sns import matplotlib import matplotlib.pyp ...

  2. SICOM SOP

    SOPs A Service-Object Pair (SOP) Class is defined by the union of an Information Object Definition ( ...

  3. CMake查找第三方库路径

    问题 一直都有一个问题,就是基于Windows下使用CMake构建VS工程时,CMake是如何查找到第三方库所在的路径的呢? 答案 今天重新想起这个问题,就拿构建Vtk的VS工程测试了一下, 才发现是 ...

  4. 【替代语法】PHP中冒号、endif、endwhile、endfor这些都是什么

    我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如: <?php if(empty($GET_['a'])): ?><font color=" ...

  5. [GoogleInterview]连续子序列问题

    Before the Beginning 本文为 Clouder 原创文章,原文链接为 https://www.codein.icu/gci-subarray/,转载时请将本段放在文章开头显眼处.如进 ...

  6. Day2-I-Knight's Problem POJ - 3985

    You must have heard of the Knight's Tour problem. In that problem, a knight is placed on an empty ch ...

  7. IOS UIPanGestureRecognizer手势使用及识别状态UIGestureRecognizerState

    UIGestureRecognizerState -- 手势识别器状态 1.先来看官方文档 定义UIGestureRecognizer.h 英文: typedef NS_ENUM(NSInteger, ...

  8. Java泛型与数组深入研究

    Java中的泛型与数组平时开发用的很多,除了偶尔遇到"NullPointerException"和"IndexOutOfBoundsException"一般也不 ...

  9. jenkins构建python项目时,提示python不是内部或外部命令的解决办法

    1.回到 Jenkins 首页,点击 “构建执行状态”或“Build Executor Status” ,右则会列出本机信息. 完美解决!!!

  10. 用 Weave Scope 监控集群【转】

    创建 Kubernetes 集群并部署容器化应用只是第一步.一旦集群运行起来,我们需要确保一起正常,所有必要组件就位并各司其职,有足够的资源满足应用的需求.Kubernetes 是一个复杂系统,运维团 ...