結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 127 ms
55,732 KB
testcase_02 AC 128 ms
55,408 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 127 ms
53,768 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 128 ms
55,724 KB
testcase_16 AC 129 ms
55,836 KB
testcase_17 AC 127 ms
55,772 KB
testcase_18 AC 137 ms
55,632 KB
testcase_19 AC 129 ms
55,640 KB
testcase_20 AC 131 ms
55,832 KB
testcase_21 AC 124 ms
55,784 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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; fst++){
				if(gcd(fst, snd) != M){ continue; }
				
				answer += (other_fact * 2) % MOD;
				answer %= MOD;
			}
		}
		
		System.out.println(answer);
	}
}
0