Description

There are n lotus leaves floating like a ring on the lake, which are numbered 0, 1, ..., n-1 respectively. The leaf 0 and n-1 are adjacent.

The frog king wants to play a jumping game. He stands at the leaf 0 initially. For each move, he jumps k (0 < k < n) steps forward. More specifically, if he is standing at the leaf x, the next position will be the leaf (x + k) % n.

After n jumps, he wants to go through all leaves on the lake and go back to the leaf 0 finally. He can not figure out how many different k can be chosen to finish the game, so he asks you for help.

Input

There are several test cases (no more than 25).

For each test case, there is a single line containing an integer n (3 ≤ n ≤ 1,000,000), denoting the number of lotus leaves.

Output

For each test case, output exactly one line containing an integer denoting the answer of the question above.

Sample Input

4
5

Sample Output

2
4

分析:

一些荷叶漂浮在湖面上其编号是0n-1,有一只青蛙初始再0位置,它每次可以跳过K个位置(0<K<n),最终跳n次回到0.求1n-1中有多少个K值满足在n此次跃中可以把每片荷叶就跳一次。

i 从 2~n-1 . 如果 n%i 取余等于0.则 i 和 i 的倍数全都不满足要求。

代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
int vis[1000000];
int main()
{
int n;
while(~scanf("%d",&n))
{
long long ans = n-1;
memset(vis,0,sizeof(vis));
for(int i = 2; i <= n/2; i++)///后一半中的如果不能够走的话,肯定有个倍数在前一半出现过
{
if(n%i == 0)
{
for(int j = i; j < n; j+=i)///往后找整数倍
{
if(vis[j]==0)
{
vis[j] = 1;
ans--;
}
}
}
}
printf("%lld\n",ans);
}
return 0;
}

2017年上海金马五校程序设计竞赛:Problem I : Frog's Jumping (找规律)的更多相关文章

  1. 2017年上海金马五校程序设计竞赛:Problem K : Treasure Map (蛇形填数)

    Description There is a robot, its task is to bury treasures in order on a N × M grids map, and each ...

  2. 2017年上海金马五校程序设计竞赛:Problem G : One for You (博弈)

    Description Given a m × n chessboard, a stone is put on the top-left corner (1, 1). Kevin and Bob ta ...

  3. 2017年上海金马五校程序设计竞赛:Problem E : Find Palindrome (字符串处理)

    Description Given a string S, which consists of lowercase characters, you need to find the longest p ...

  4. 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)

    Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...

  5. 2017年上海金马五校程序设计竞赛:Problem B : Sailing (广搜)

    Description Handoku is sailing on a lake at the North Pole. The lake can be considered as a two-dime ...

  6. 2017年上海金马五校程序设计竞赛:Problem A : STEED Cards (STL全排列函数)

    Description Corn does not participate the STEED contest, but he is interested in the word "STEE ...

  7. 2017Summmer_上海金马五校 F题,G题,I题,K题,J题

    以下题目均自己搜 F题  A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...

  8. HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)

    题目链接  2016 CCPC东北地区大学生程序设计竞赛 B题 题意  给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...

  9. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

随机推荐

  1. mysql 大数据分页查询优化

    应用场景: 当有一张表的数据非常大,需要使用到分页查询,分页查询在100w条后查询效率非常低: 解决方案: 1.业务层解决:只允许用户翻页一百页以内,十条一页: 2.使用where id > 5 ...

  2. javac一次性编译多个包下的.java文件

    如题是我想要知道的,然后在网上搜了一下 下面是在某些帖子里看到别人说的只言片语 =========================================================== ...

  3. 使用hibernate连接Oracle时的权限问题

    在使用hibernate对象关系映射连接和创建表的时候,会涉及到很多权限问题,有些数据库管理会将权限设的很细,我们可以根据后台日志错误和异常信息作出判断. 比如下图所示这个错误(这是我在给银行投产系统 ...

  4. Java并发基础--线程通信

    java中实现线程通信的四种方式 1.synchronized同步 多个线程之间可以借助synchronized关键字来进行间接通信,本质上是通过共享对象进行通信.如下: public class S ...

  5. 用Fluent实现MySQL到ODPS数据集成

    安装ruby 首先通过 /etc/issue 命令查看当前使用centos是哪个版本: [hadoop@hadoop03 ~]$  cat /etc/issue 由于centos版本是6.6,安装ru ...

  6. [OpenCV]DMatch类和KeyPoints类:特征点匹配

    DMatch struct CV_EXPORTS_W_SIMPLE DMatch { CV_WRAP DMatch() : queryIdx(-), trainIdx(-), imgIdx(-), d ...

  7. Word2Vec词向量(一)

    一.词向量基础(一)来源背景  word2vec是google在2013年推出的一个NLP工具,它的特点是将所有的词向量化,这样词与词之间就可以定量的去度量他们之间的关系,挖掘词之间的联系.虽然源码是 ...

  8. 《Deep Learning》第二章 线性代数 笔记

    第二章 线性代数 2.1 名词 标量(scalar).向量(vector).矩阵(matrix).张量(tensor) 2.2 矩阵和向量相乘 1. 正常矩阵乘法: 2. 向量点积: 3. Hadam ...

  9. Tensorflow编程基础之Mnist手写识别实验+关于cross_entropy的理解

    好久没有静下心来写点东西了,最近好像又回到了高中时候的状态,休息不好,无法全心学习,恶性循环,现在终于调整的好一点了,听着纯音乐突然非常伤感,那些曾经快乐的大学时光啊,突然又慢慢的一下子出现在了眼前, ...

  10. 安装一台Linux练习机前的考虑——主机规划与磁盘分区

    要安装一台Linux主机并不是那么简单的事,我们必须要针对distributions的特性.服务器软件的能力.未来的升级需求.硬件扩充性需求等来考虑,对于磁盘分区.文件系统.Linux操作较频繁的目录 ...