2017年上海金马五校程序设计竞赛:Problem I : Frog's Jumping (找规律)
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 (找规律)的更多相关文章
- 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 ...
- 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 ...
- 2017年上海金马五校程序设计竞赛:Problem E : Find Palindrome (字符串处理)
Description Given a string S, which consists of lowercase characters, you need to find the longest p ...
- 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)
Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...
- 2017年上海金马五校程序设计竞赛:Problem B : Sailing (广搜)
Description Handoku is sailing on a lake at the North Pole. The lake can be considered as a two-dime ...
- 2017年上海金马五校程序设计竞赛:Problem A : STEED Cards (STL全排列函数)
Description Corn does not participate the STEED contest, but he is interested in the word "STEE ...
- 2017Summmer_上海金马五校 F题,G题,I题,K题,J题
以下题目均自己搜 F题 A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...
- HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)
题目链接 2016 CCPC东北地区大学生程序设计竞赛 B题 题意 给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
随机推荐
- How to Upload multiple files to documentLibrary in one time
In a Sharepoint 2013 website,we can upload one file to the documentlibrary by click "Uploa ...
- 【个人训练】(POJ3279)Fliptile
最近在刷kuangbin神犇的各种套题....感觉自己好弱啊.....还是要多多训练,跟上大神的脚步.最近的这十几题都比较水,记下来这一条我比较印象深刻.也比较难的题目吧(之后应该不会再有水题写了,珍 ...
- MUI scroll 定位问题
做一个微信项目,使用MUI做框架,在使用scroll定位的时候,出现了定位不准确的问题,查询了好多资料,得知他是相对定位.折腾了好久,才搞定,现在做一个笔记. mui('body').on('tap' ...
- hadoop自定义数据类型
统计某手机数据库的每个手机号的上行数据包数量和下行数据包数量 数据库类型如下: 数据库内容如下: 下面自定义类型SimLines,类似于平时编写的model import java.io.DataIn ...
- C++编码规范101
组织和策略问题 第0条 不要拘泥于小节(又名:了解哪些东西不应该标准化) 第1条 在高警告级别干净利落地进行编译 第2条 使用自动构建系统 第3条 使用版本控制系统 第4条 在代码审查上投入 设计风格 ...
- 算法(2) Find All Numbers Disappeared in an Array
题目:整数数组满足1<=a[i]<=n(n是数组的长度),某些元素出现一次,某些元素出现两次,在数组a[i]中找到[1,n]区间中未出现的数字.比如输入[4,3,2,7,8,2,3,1], ...
- 【bzoj2957】楼房重建 分块+二分查找
题目描述 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子.为了简化问题,我们考虑这些事件发生在一个二 ...
- gdkoi前的复习
又浪了一天…… 整理下学的,这两天都温习(预习)一下吧. 27号就是gdkoi了好怕…… 数据结构 ------树 -------------平衡树 -------------线段树/树状数组 --- ...
- [ZJOI2006]物流运输 DP 最短路
---题面--- 题解: 设f[i]表示到第i天的代价,cost[i][j]表示第i天到第j天采取同一种方案的最小代价.那么转移就很明显了,直接$n^2$枚举即可. 所以问题就变成了怎么获取cost数 ...
- Android逆向之旅---爆破一款资讯类应用「最右」防抓包策略原理分析
一.逆向分析 首先感谢王同学提供的样本,因为王同学那天找到我咨询我说有一个应用Fiddler抓包失败,其实对于这类问题,我一般都会这么回答:第一你是否安装Fiddler证书了,他说他安装了.第二你是否 ...