Chinese Girls' Amusement

Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu

Description

      You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chinese habits seem quite unusual or even weird to us. 
      So it is known that there is one popular game of Chinese girls. N girls stand forming a circle and throw a ball to each other. First girl holding a ball throws it to the K-th girl on her left (1 ≤ K ≤ N/2). That girl catches the ball and in turn throws it to the K-th girl on her left, and so on. So the ball is passed from one girl to another until it comes back to the first girl. If for example N = 7 and K = 3, the girls receive the ball in the following order: 1, 4, 7, 3, 6, 2, 5, 1. 
 To make the game even more interesting the girls want to choose K as large as possible, but they want one condition to hold: each girl must own the ball during the game.

Input

Input contains one integer number N (3 ≤ N ≤ 10 2000) — the number of Chinese girls taking part in the game.

Output

Output the only number — K that they should choose.

Sample Input

7
6

Sample Output

3
1
题意:给定一个很大的数N,求一个数K,K大于等于1小于等于N/2,使得gcd(N,K)=1。
题解:打表可以发现规律。
打表可以发现规律 奇数就是除以2  偶数如果是4的倍数则除以2减1 偶数如果非4的倍数则除以2减2
接下来就是代码的实现了,用字符串存储数组。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int a[],b[];
char c[];
while(scanf("%s",c)!=EOF)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int len=strlen(c);
int cnt=;
for(int i=; i<len; i++)
a[i]=c[i]-'';
for(int i=; i<len; i++)
{
b[i]=(a[i]+cnt*)/;
if(a[i]%==)
cnt=;
else
cnt=;
}
int jian=;
int sum=a[len-]*+a[len-];
//奇数就是除以2 偶数4的倍数除以2减1 偶数非4的倍数除以2减2
if(sum%==)
{
if(sum%==)
jian=;
else
jian=;
}
int sumb=,k=;
if(jian==)
{
int flag1=;
for(int i=len-; i>=; i--)
{
if(b[i]==)
{
flag1=;
continue;
}
else
{
k=i;
for(int j=k;j<len-;j++)
b[j]--;
if(flag1)
b[len-]=;
else
b[len-]--;
break;
}
}
}
else if(jian==) //
{
int flag=;
int flag2=;
if(b[len-]>=) //这个和上面的len-1不一样
{
b[len-]-=;
flag=;
flag2=;
}
for(int i=len-; i>=; i--) //最后一位肯定不行的
{
if(flag)
break;
if(b[i]==)
{
flag2=;
continue;
}
else
{//
k=i;
for(int j=k;j<len-;j++)
b[j]--;
b[len-]=b[len-]+-;
break;
}
}
}
int j=;
while(b[j]==) j++;
for(; j<len; j++)
printf("%d",b[j]);
printf("\n");
} return ;
}

最新文章

  1. Win10计算器在哪里?三种可以打开Win10计算器的方法图文介绍
  2. OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)
  3. 《笨办法学C》笔记之Makefile
  4. LogViewer - 方便的日志查看工具
  5. 20145225 实验四《Andoid开发基础》
  6. oracle 树状查询
  7. ionic中登陆逻辑控制
  8. mikrotik/IPSec Dynamic End points Updater.rsc
  9. [Yii2]Access to debugger is denied due to IP address restriction. The requesting IP address is
  10. 布局—column(属性)
  11. 跨平台移动框架iMAG开发入门
  12. Partial Tree
  13. Beta冲刺 第六天
  14. zookeeper 分布式锁原理
  15. windows 10 &amp; 禁用服务.bat
  16. Vector集合
  17. C# 绘图时使用抗锯齿会多出一个像素
  18. 机器学习之决策树_CART算法
  19. Python shutil 模块
  20. GUI学习之一——PyQt5初识

热门文章

  1. vue 点击当前元素添加class 去掉兄弟的class
  2. php中const与static的区别与使用(转)
  3. Error: Cannot find module &#39;core-js/fn/array/values&#39; at Function.Module._resolveFilename (module
  4. 11-Json文件配置
  5. SharpCompress的压缩文件解压和文件夹压缩
  6. Nodejs-异步操作
  7. Django 2.0官方文档中文 总索引
  8. 剑指Offer - 九度1372 - 最大子向量和(连续子数组的最大和)
  9. JMeter学习笔记(十一) 关于 CSV Data Set Config 的 Sharing mode 对取值的影响
  10. MVC学习笔记---WebViewPage(nop等开源项目的@T)