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 < 231), 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.

Example

Input:
3
4
5
18
36
360
2147483647 Output:
1
1
2
3
6
48
1073741823

题意:给出一个圆,圆上有n个点,以任一点为起点,每次可以向一个方向连到第k个点(距离本身),问有多少种连法,可以吧所有的点都连上

思路:画图可以简单的归纳出,每次向前的点数k,必须符合gcd(k,n)=1,才能把所有点都连上

又因为呢 向前k个点和向前(n-k)个点的方法其实是一样的因此总的方法数就是小于n且与n互质得数的个数除以2;

也就是欧拉函数 euler(n)/2;

起初做这道题的时候以为是道规律题,找了半天规律,自找对了n为偶数的情况,奇数一直以为直接初二(其实是质数直接除二,怪自己找的样例太个别)

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#define Mod 1000000007
using namespace std;
typedef long long ll;
const ll N = +;
map<ll,ll> elh;
long long a,b;
ll sum [N];
ll Euler(ll n)
{
ll res =n;
for(ll i=;i<=n/i;i++)
{
if(n%i==)
{
res = res -res/i;
}
while(n%i==)n/=i;
}
if(n>)res -= res/n;
return res;
}
int main()
{
while(~scanf("%lld",&a))
{
cout <<Euler(a)/<<endl;
}
return ;
}

F - Star SPOJ - STARSBC的更多相关文章

  1. Just oj 2018 C语言程序设计竞赛(高级组)F:Star(结构体排序+最小生成树)

    F: Star Time Limit: 1 s      Memory Limit: 128 MB Submit My Status Problem Description 31世纪,人类世界的科技已 ...

  2. 【Redis】简介与安装

    Linux 安装 [root@redis ~]# wget http://download.redis.io/releases/redis-2.8.19.tar.gz 解压缩redis[root@ha ...

  3. Correlation Filter in Visual Tracking系列一:Visual Object Tracking using Adaptive Correlation Filters 论文笔记

    Visual Object Tracking using Adaptive Correlation Filters 一文发表于2010的CVPR上,是笔者所知的第一篇将correlation filt ...

  4. 2014联合三所学校 (HDU 4888 HDU 4891 HDU 4893)

    HDU 4891 The Great Pan 注册标题  他怎么说,你怎么样  需要注意的是乘法时,它会爆炸int 代码: #include<iostream> #include<c ...

  5. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  6. 有趣的F-String

    F-String 让人上瘾 一个工具脚本的例子 https://www.pydanny.com/python-f-string-are-fun.html 在Python3.6的发布中,我们看到他们采纳 ...

  7. hdu 5126 cdq+Treap+BIT

    这题说的是给了三维空间然后操作 寻求在 x1,y1,z1    x2, y2, z2; (x1<x2, y1<y2,z1<z2) 计算出在 以这两个端点为右下和左上端点的方体内的点的 ...

  8. JavaScript cookie操作实现点赞功能

    JavaScript cookie操作实现点赞功能 参考实现原理,但是代码不够简洁,简洁代码参考:js操作cookie 实现一个点赞功能十分简单,主要问题在于不能重复点赞.  若是一个有用户的网站,可 ...

  9. Haskell语言学习笔记(45)Profunctor

    Profunctor class Profunctor p where dimap :: (a -> b) -> (c -> d) -> p b c -> p a d d ...

随机推荐

  1. 码云配置WebHook自动更新

    配置项目提交到git的时候自动同步服务器代码 一.在服务器项目跟目录新建文件hook.php 代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php $json =  ...

  2. 图像欧拉数计算 matlab实现

    EUL = C - H 其中EUL表示欧拉数  C表示对象数 H表示孔洞数 欧拉数常用来识别数字: 识别数字 8 ,8 的欧拉数为 -1 ,不同于0,1,2,3,4,5,6,7,9 close all ...

  3. 简单记录一下虚拟机中安装Linux的流程以及部分软件的安装命令

    一,虚拟机使用的是VMware9 ,linux使用的是服务器中用的比较多的CentOS6.4.稍后我会把这两个版本放到网盘中,需要的朋友可以去下载: 网盘地址: 二,VM的安装比较简单,基本上按照网上 ...

  4. 最新 光环新网java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.优刻得等10家互联网公司的校招Offer,因为某些自身原因最终选择了优刻得.6.7月主要是做系统复习.项目复盘.LeetCo ...

  5. 计算1-9总共九个数字可以满足abc+def=hij这样的式子

    计算1-9总共九个数字可以满足abc+def=hij这样的式子:其中abcdefghij九个数字各个都不相同,它们都属于1-9个数字中: 首先,第一种方法很简单很暴力,直接枚举,这样的话时间复杂度高: ...

  6. noi openjudge7627:鸡蛋的硬度

    http://noi.openjudge.cn/ch0206/7627/ 描述 最近XX公司举办了一个奇怪的比赛:鸡蛋硬度之王争霸赛.参赛者是来自世界各地的母鸡,比赛的内容是看谁下的蛋最硬,更奇怪的是 ...

  7. 【SVN】总结:svn“Previous operation has not finished; run 'cleanup' if it was interrupted“

    svn执行clean up命令时报错“Previous operation has not finished; run 'cleanup' if it was interrupted”.无论你到那个父 ...

  8. 初识gRPC

    一.gRPC的概念 gRPC是Google推出的一个开源高性能的轻量级RPC框架,可以在任何环境中运行.它可以有效地连接数据中心内和跨数据中心的服务,并提供可插拔的支持,以实现负载平衡,跟踪,健康检查 ...

  9. UWP笔记-使用FFmpeg编解码

    在开发UWP媒体应用的时候,使用的MediaElement可以支持主流的格式,不过还是有些格式本地编解码器是不支持的,如.flv..rmvb等,这里讲到的是第三方开源库FFmpeg,可以直接播放更多的 ...

  10. Django生成数据表时报错

    Django生成数据表时报错 WARNINGS: ?: (mysql.W002) MySQL Strict Mode is not set for database connection 'defau ...