結果

問題 No.644 G L C C D M
ユーザー uafr_csuafr_cs
提出日時 2018-02-02 22:27:55
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 812 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 71,868 KB
実行使用メモリ 64,620 KB
最終ジャッジ日時 2023-08-30 02:16:52
合計ジャッジ時間 8,563 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	public static long lcm(long a, long b){
		return a / gcd(a, b) * b;
	}
	
	public static final long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long N = sc.nextLong();
		final long M = sc.nextLong();
		
		long other_fact = 1;
		for(int i = 1; i <= (N - 2); i++){
			other_fact *= i;
			other_fact %= MOD;
		}
		
		long answer = 0;
		for(int fst = 1; fst <= N; fst++){
			for(int snd = fst + 1; fst <= N; snd++){
				if(gcd(fst, snd) != M){ continue; }
				
				answer += (other_fact * 2) % MOD;
				answer %= MOD;
			}
		}
		
		System.out.println(answer);
	}
}
0