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