結果

問題 No.2610 Decreasing LCMs
ユーザー uwiuwi
提出日時 2024-01-20 17:30:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 1,000 ms
コード長 2,815 bytes
コンパイル時間 4,316 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 58,212 KB
最終ジャッジ日時 2024-01-20 17:30:31
合計ジャッジ時間 9,300 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
57,824 KB
testcase_01 AC 150 ms
57,916 KB
testcase_02 AC 158 ms
57,948 KB
testcase_03 AC 149 ms
58,212 KB
testcase_04 AC 150 ms
58,108 KB
testcase_05 AC 151 ms
58,080 KB
testcase_06 AC 149 ms
58,092 KB
testcase_07 AC 147 ms
58,112 KB
testcase_08 AC 147 ms
58,092 KB
testcase_09 AC 148 ms
58,100 KB
testcase_10 AC 148 ms
58,088 KB
testcase_11 AC 148 ms
58,208 KB
testcase_12 AC 146 ms
58,104 KB
testcase_13 AC 149 ms
58,092 KB
testcase_14 AC 149 ms
58,084 KB
testcase_15 AC 147 ms
58,212 KB
testcase_16 AC 149 ms
58,072 KB
testcase_17 AC 149 ms
58,080 KB
testcase_18 AC 148 ms
58,088 KB
testcase_19 AC 148 ms
58,208 KB
testcase_20 AC 150 ms
58,084 KB
testcase_21 AC 149 ms
58,108 KB
testcase_22 AC 150 ms
58,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no2xxx;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class No2610_2 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
		int[] a = new int[25];
		a[0] = 720719;
		a[1] = 720720;
		outer:
		for(int i = 2;i < 25;i++){
			for(a[i] = a[i-1] + a[i-1] - a[i-2] + 1;;a[i]++){
				int t = a[i] - a[i-1];
				if(a[i] % t == 0 && a[i-2] / (a[i-1] - a[i-2]) > a[i] / (a[i] - a[i-1])){
//					tr(a);
					continue outer;
				}
			}
		}
//		tr(a);
		int n = ni();
		for(int i = 0;i < n;i++){
			out.print(a[i] + " ");
		}
		out.println();
	}

	public static int gcd(int a, int b) {
		while (b > 0) {
			int c = a;
			a = b;
			b = c % b;
		}
		return a;
	}


	public static boolean inc(int[] a, int base) {
		int n = a.length;
		int i;
		for (i = n - 1; i >= 0 && a[i] == base - 1; i--) ;
		if (i == -1) return false;

		a[i]++;
		Arrays.fill(a, i + 1, n, 0);
		return true;
	}


	public static int[] sieveEratosthenes(int n) {
		if (n <= 32) {
			int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
			for (int i = 0; i < primes.length; i++) {
				if (n < primes[i]) {
					return Arrays.copyOf(primes, i);
				}
			}
			return primes;
		}

		int u = n + 32;
		double lu = Math.log(u);
		int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
		ret[0] = 2;
		int pos = 1;

		int[] isnp = new int[(n + 1) / 32 / 2 + 1];
		int sup = (n + 1) / 32 / 2 + 1;

		int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
		for (int tp : tprimes) {
			ret[pos++] = tp;
			int[] ptn = new int[tp];
			for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31);
			for (int j = 0; j < sup; j += tp) {
				for (int i = 0; i < tp && i + j < sup; i++) {
					isnp[j + i] |= ptn[i];
				}
			}
		}

		// 3,5,7
		// 2x+3=n
		int[] magic = {0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14};
		int h = n / 2;
		for (int i = 0; i < sup; i++) {
			for (int j = ~isnp[i]; j != 0; j &= j - 1) {
				int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
				int p = 2 * pp + 3;
				if (p > n) break;
				ret[pos++] = p;
				if ((long) p * p > n) continue;
				for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q;
			}
		}

		return Arrays.copyOf(ret, pos);
	}


	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0