1 条题解
-
0
C :
#include<stdio.h> int main( int argc, char ** argv ) { int Step, Mod; while( scanf( "%d%d", &Step, &Mod ) != EOF ) { int Book[100001] = { 0 }; int Count = 0, S = 0; while( Book[S] == 0 ) { Book[S] = 1; S = ( S + Step) % Mod; Count++; } if( Count == Mod ) printf( "%10d%10d Good Choice\n", Step, Mod ); else printf( "%10d%10d Bad Choice\n", Step, Mod ); } return 0; }
C++ :
#include<stdio.h> #include<iostream> #include<string.h> using namespace std; int f[100000]; int main() { int step, mod; // step,mod int i, a; bool tag; while (cin >> step >> mod) { memset(f, 0, sizeof(f)); tag = true; a = 0; f[a]++; for (i = 1; i < mod; i++) { a = (a + step) % mod; f[a]++; if (f[a] >= 2) { tag = false; break; } } printf("%10d%10d ", step, mod); // 打印10位数 if (tag) cout << "Good Choice" << endl; else cout << "Bad Choice" << endl; } return 0; }
Java :
import java.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()){ int step =in.nextInt(); int mod =in.nextInt(); boolean[] flag = new boolean[mod]; Arrays.fill(flag, false); int step1 = 1; boolean B = true; for(int i=0;i<mod;i++){ step1 =(step1+step)%mod; if(flag[step1]==false) flag[step1] = true; else{ B=false; break; } } if(B == false){ System.out.printf("%10d%10d",step,mod); System.out.println(" "+"Bad Choice"); } else{ System.out.printf("%10d%10d",step,mod); System.out.println(" "+"Good Choice"); } } } }
- 1
信息
- ID
- 1165
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者