Problem I : Frog's Jumping
From: DHUOJ, 2017060309
(Out of Contest)
一些荷叶漂浮在湖面上其编号是0~n-1,有一只青蛙初始再0位置,它每次可以跳过K个位置(0<K<n),最终跳n次回到0.求1~n-1中有多少个
K值满足在n此次跃中可以把每片荷叶就跳一次。
解题思路:
简单题,i 从 2~n-1 . 如果 n%i 取余等于0.则 i 和 i 的倍数全都不满足要求。就是n值有点大,怪吓人的,但是暴力2层for循环就过了。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 1000000;
int vis[maxn];
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;
}