結果

問題 No.420 mod2漸化式
ユーザー GrenacheGrenache
提出日時 2016-09-10 11:05:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 4,584 bytes
コンパイル時間 4,015 ms
コンパイル使用メモリ 76,144 KB
実行使用メモリ 58,036 KB
最終ジャッジ日時 2023-08-25 23:29:50
合計ジャッジ時間 10,138 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,068 KB
testcase_01 AC 122 ms
55,832 KB
testcase_02 AC 122 ms
55,608 KB
testcase_03 AC 126 ms
56,012 KB
testcase_04 AC 127 ms
56,048 KB
testcase_05 AC 125 ms
55,824 KB
testcase_06 AC 125 ms
55,924 KB
testcase_07 AC 124 ms
56,008 KB
testcase_08 AC 122 ms
56,348 KB
testcase_09 AC 123 ms
56,020 KB
testcase_10 AC 124 ms
55,680 KB
testcase_11 AC 125 ms
55,904 KB
testcase_12 AC 120 ms
55,440 KB
testcase_13 AC 124 ms
58,036 KB
testcase_14 AC 123 ms
55,824 KB
testcase_15 AC 123 ms
55,900 KB
testcase_16 AC 123 ms
55,900 KB
testcase_17 AC 123 ms
54,260 KB
testcase_18 AC 124 ms
55,988 KB
testcase_19 AC 124 ms
56,216 KB
testcase_20 AC 123 ms
55,680 KB
testcase_21 AC 125 ms
56,284 KB
testcase_22 AC 123 ms
55,916 KB
testcase_23 AC 124 ms
56,044 KB
testcase_24 AC 124 ms
55,416 KB
testcase_25 AC 122 ms
55,604 KB
testcase_26 AC 125 ms
55,916 KB
testcase_27 AC 123 ms
56,044 KB
testcase_28 AC 122 ms
55,600 KB
testcase_29 AC 122 ms
55,464 KB
testcase_30 AC 123 ms
55,820 KB
testcase_31 AC 125 ms
55,612 KB
testcase_32 AC 123 ms
55,876 KB
testcase_33 AC 122 ms
55,548 KB
testcase_34 AC 122 ms
55,536 KB
testcase_35 AC 122 ms
55,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder420 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int x = sc.nextInt();

		if (x > 31) {
			pr.printf("%d %d\n", 0, 0);
		} else if (x == 0) {
			pr.printf("%d %d\n", 1, 0);
//		} else if (x == 31) {
//			long ret = (0x1L << 31) - 1;
//			pr.printf("%d %d\n", 1, ret);
		} else {
			long ret = 0;
			ret = ((0x1L << 31) - 1) * PC.CLong(30, x - 1);

			pr.printf("%d %d\n", PC.CLong(31, x), ret);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
    private static class PC {
    	// MOD must be prime number.
    	int MOD;
    	// fact[i] : i! % MOD
    	long[] fact;
    	// ifact[i] : 1/i! % MOD
    	long[] ifact;

    	PC(int size, int MOD) {
    		// O(size)
    		// n=sizeまでのnCrを求める。
    		// nHrはn+r-1Crになってしまうので注意

    		this.MOD = MOD;

    		fact = new long[size + 1];
    		fact[0] = 1;
    		for (int i = 1; i <= size; i++) {
    			fact[i] = fact[i - 1] * i % MOD;
    		}

    		ifact = new long[size + 1];

    		int loop = MOD - 2;
    		long x = fact[size];
    		ifact[size] = 1;
    		while (loop > 0) {
    			if (loop % 2 == 1) {
    				ifact[size] = ifact[size] * x % MOD;
    			}
    			x = x * x % MOD;
    			loop /= 2;
    		}

    		for (int i = size - 1; i >= 0; i--) {
    			ifact[i] = ifact[i + 1] * (i + 1) % MOD;
    		}

    	}

    	// 組合せの数
    	int C(int n, int r) {
    		if (r > n) {
    			return 0;
    		}

    		return (int)(((fact[n] * ifact[n - r]) % MOD) * ifact[r] % MOD);
    	}

    	// 順列
    	int P(int n, int r) {
    		if (r > n) {
    			return 0;
    		}

    		return (int)((fact[n] * ifact[n -r]) % MOD);
    	}

    	// 重複組み合わせ
    	// 異なるn種のものから重複を許してr個を選ぶ場合の数
    	// 0個の種類もあり得る
    	int H(int n, int r) {
    		if (n == 0 && r == 0) {
    			return 1;
    		}

    		return C(n + r - 1, r);
    	}

    	// 組合せの数(nが大きいとき)
    	//   O(r)で求めることができる。rはsizeの大きさまで
    	int C2(long n, int r) {
    		long ret = ifact[r];
    		for (int i = 1; i <= r; i++) {
    			long tmp = (n - r + i) % MOD;
    			ret = (ret * tmp) % MOD;
    		}

    		return (int)ret;
    	}

    	// 第2種スターリング数
    	// n人をちょうどr個のグループに分ける(グループの区別はなし)
    	// グループの区別をする場合はr!S(n,r)。全射の場合の数と同義
    	// O(r log n)
    	int S(long n, int r) {
    		//全射の場合の数を包除原理を使って求めて、1/r!をかける。
    		long ret = 0;
    		for (int i = 1; i <= r; i++) {
    			long tmp = (r - i) % 2 == 0 ? 1 : -1;
    			tmp *= pow(i, n) * C(r, i) % MOD;
    			ret = (ret + tmp + MOD) % MOD;
    		}
    		ret = ret * ifact[r] % MOD;

    		return (int)ret;
    	}

    	long pow(int a, long n) {
    		long loop = n;
    		long ret = 1;
    		long x = a;
    		while (loop > 0) {
    			if (loop % 2 == 1) {
    				ret = ret * x % MOD;
    			}
    			x = x * x % MOD;
    			loop /= 2;
    		}

    		return ret;
    	}

    	// 組合せの数
    	// パスカルの三角形MODなし
		// 限界:n=66 : 66C33=7219428434016265740
    	private final static int LIMIT = 66;
    	private static int to;
    	private static long[][] cache;

    	static long CLong(int n, int r) {
    		if (r > n) {
    			return 0;
    		}

    		if (n > LIMIT) {
    			throw new IllegalArgumentException(Integer.toString(n));
    		}

    		if (cache == null) {
    			cache = new long[LIMIT + 1][];
    			cache[0] = new long[1];
    			cache[0][0] = 1;
    			to = 0;
    		}

    		if (cache[n] == null) {
    			for (int i = to + 1; i <= n; i++) {
    				cache[i] = new long[i + 1];
    				for (int j = 0; j <= i; j++) {
    					if (j == 0 || j == i) {
    						cache[i][j] = 1;
    					} else {
    						if (Long.MAX_VALUE - cache[i - 1][j - 1] < cache[i - 1][j]) {
    			    			throw new IllegalArgumentException("Overflow");
    						} else {
    							cache[i][j] = cache[i - 1][j - 1] + cache[i - 1][j];
    						}
    					}
    				}
    			}
    			to = n;
    		}

    		return cache[n][r];
    	}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0