flavius.java

来自「Ulm大学2005-2006年竞赛题」· Java 代码 · 共 27 行

JAVA
27
字号
import java.io.*;import java.util.*;public class flavius {	public static void main(String [] args) throws Exception {		int n;		Scanner in = new Scanner(new File("flavius.in"));		while((n = in.nextInt()) != 0) {			int a = in.nextInt();			int b = in.nextInt();			long x = 0;			HashMap<Integer,Integer> visit = new HashMap<Integer,Integer>();			int c = 0;			while(true) {				++c;				if (visit.get((int)x) != null) {					int t = visit.get((int)x);					System.out.println(n-(c-t));					break;				}				visit.put((int)x,c);				x = ((((x*x)%n)*a)%n+b)%n;			}		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?