Yesterday did a few topics, too simple, it is not written in the blog.
1314 This problem is also relatively simple, written out because I think there is a small trick, for time complexity and space complexity are more economical.
This topic is similar to the solution of a hash table, but simpler. When I got the title, I took it for granted that I wanted to put the query results in an array, and then traverse the query for the same mod value. But the feeling is certainly the most common method and not too efficient.
Later thought of some other query algorithms, such as two points, but it is not very appropriate to feel. Until I realized that this process is similar to the process of calculating a hash table, so directly using the MoD value as the subscript index of the array, you can directly navigate to whether the current value has been computed, so as to quickly determine whether a good loop.
public class Main {public static void main (String argv[]) {int Step, mod;java.util.scanner Scanner = new Java.util.Scanner (system.in); while (Scanner.hasnext ()) {String strLine = Scanner.nextline (); String strnums[] = Strline.split (""); Step = Integer.parseint (Strnums[0]); Mod = Integer.parseint (strnums[1]), int mods[] = new Int[mod];mods[0] = 0;int seed = 0; String strresult = "good Choice"; for (int i=1;i<mod;i++) {seed = (seed + Step)% mod;if (mods[seed] = = 0 && seed ! = 0) {Mods[seed] = seed;} else {strresult = "bad Choice"; break;}} System.out.format ("%10s", Step); System.out.format ("%10s", Mod); System.out.println (" " +strresult+ "\ n");}}}