Star (欧拉函数)
题面
Fernando won a compass for his birthday, and now his favorite hobby is drawing stars: first, he marks N points on a circumference, dividing it into N equal arcs; then, he connects each point to the k-th next point, until returning to the first point.
Depending on the value of k, Fernando may or may not reach all points marked on the circumference; when that happens, the star is called complete. For example, when N = 8, the possible stars are shown in the figure below. Stars (a) and (c) are complete, while stars (b) and (d) are not.
Depending on the value of N, it may be possible to draw many different stars; Fernando asked you to write a program that, given N, determines the number of complete stars he can draw.
Input
The input contains several test cases. Each test case contains a single line, containing a single integer N (3 ≤ N < 2^31), indicating the number of arcs in which the circumference was divided.
Output
For each test case, your program must print a single line containing a single integer, indicating the number of complete stars that can be drawn.
题解
考虑这个圆上的一个点为起点

如果选择一个距离 K 使之可以被遍历完,那么一定有一个时候,它可以跳到与A相邻的B点,这是肯定的吧

反过来说,如果对于某个K,跳的次数为X,如果 XK mod N = 1,那么K一定是一种合法方案,
这是不是就意味着,X是K关于N的逆元?
我们知道,K有关于N的逆元的条件是K与N互质,
那么答案就为 φ(N) / 2
为什么要除以二呢,因为 K = p 和 K = N - p画出来的图长得一样,
CODE
(笔者vjudge暂时被封)
(以下是Alzh的代码)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
LL Euler(LL n)
{
LL res=n;
for(LL i=2; i*i<=n; ++i)
{
if(n%i==0)
{
res=res/i*(i-1);
while(n%i==0)
n/=i;
}
}
if(n>1)
res=res/n*(n-1);
return res;
}
int main()
{
LL n;
while(~scanf("%lld",&n))
printf("%lld\n",Euler(n)/2);
return 0;
}
Star (欧拉函数)的更多相关文章
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- COGS2531. [HZOI 2016]函数的美 打表+欧拉函数
题目:http://cogs.pw/cogs/problem/problem.php?pid=2533 这道题考察打表观察规律. 发现对f的定义实际是递归式的 f(n,k) = f(0,f(n-1,k ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- 51Nod-1136 欧拉函数
51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1136 1136 欧拉函数 基准时间限制:1 秒 空间限制: ...
- 欧拉函数 - HDU1286
欧拉函数的作用: 有[1,2.....n]这样一个集合,f(n)=这个集合中与n互质的元素的个数.欧拉函数描述了一些列与这个f(n)有关的一些性质,如下: 1.令p为一个素数,n = p ^ k,则 ...
- FZU 1759 欧拉函数 降幂公式
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000 ...
- hdu 3307 Description has only two Sentences (欧拉函数+快速幂)
Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- c++ 超大整数除法 高精度除法
c++ 超大整数除法 高精度除法 解题思路 计算a/b,其中a为大整数,b为普通整数,商为c,余数为r. 根据手算除法的规则,上一步的余数记为r,则本次计算的被除数为t=r*10+被除数的本位数值a[ ...
- java提前工作、第一个程序
java提前工作 我们学习编程肯定会 运用到相应的软件 在这里 我个人推荐 eclipse.idea 这里的软件呢 都是用我们的java编程出来的,那它也需要用java来支持他的开发环境 这里就运用到 ...
- 爱快在PVE下不定时反复重启死机的解决方法
太长不看版本: 爱快3.6.X在PVE乃至于ESXI下都存在一定的兼容问题! 官网下载3.6.X安装后进入系统设置-升级备份-版本升级,使用爱快3.4.9bin升降级包,下载其中的bin升降级包,将爱 ...
- 3.shell脚本循环试题
shell脚本循环试题 1.计算从1到100所有整数的和 #!/bin/bash a=0 for i in {1..100} #1到100 #每次循环变量i的值也为循环次数 do a=$[ $a + ...
- 【Redis】Redis Cluster-集群故障转移
集群故障转移 节点下线 在集群定时任务clusterCron中,会遍历集群中的节点,对每个节点进行检查,判断节点是否下线.与节点下线相关的状态有两个,分别为CLUSTER_NODE_PFAIL和CLU ...
- vue 封装弹窗组件注意
父组件 <template> <div> <p @click="onDelete"> 打开 </p> <!-- 弹框 --&g ...
- StringJoiner的使用
1.添加字符串 add()方法 StringJoiner sj = new StringJoiner(","); sj.add("我爱你"); sj.add(& ...
- 图片管够!用Python做了个图片识别系统(附源码)
本项目将使用python3去识别图片是否为色情图片,会使用到PIL这个图像处理库,并且编写算法来划分图像的皮肤区域 介绍一下PIL: PIL(Python Image Library)是一种免费的图像 ...
- python各种BUG报错解决
报错1 python学习交流群:660193417### Could not build atari-py: Command '['cmake', '..']' returned non-zero e ...
- 如何将 DevSecOps 引入企业?
前 言 现如今,大部分企业已经在内部实现了 DevOps 实践.DevOps 为团队提供了交付可靠软件和快速更新的方法论.这种方法让团队更专注于质量而不是将时间浪费在运维上.然而,结果是,安全实践往往 ...