結果

問題 No.644 G L C C D M
ユーザー uafr_csuafr_cs
提出日時 2018-02-02 23:16:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,278 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 74,204 KB
実行使用メモリ 56,248 KB
最終ジャッジ日時 2023-08-30 02:28:27
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,948 KB
testcase_01 AC 126 ms
55,868 KB
testcase_02 AC 125 ms
55,872 KB
testcase_03 AC 127 ms
56,244 KB
testcase_04 AC 128 ms
55,572 KB
testcase_05 AC 125 ms
56,056 KB
testcase_06 WA -
testcase_07 AC 124 ms
55,776 KB
testcase_08 WA -
testcase_09 AC 126 ms
56,024 KB
testcase_10 AC 127 ms
55,568 KB
testcase_11 WA -
testcase_12 AC 126 ms
55,972 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 126 ms
55,644 KB
testcase_16 AC 126 ms
55,824 KB
testcase_17 AC 124 ms
55,888 KB
testcase_18 AC 131 ms
56,248 KB
testcase_19 AC 126 ms
56,008 KB
testcase_20 AC 130 ms
55,956 KB
testcase_21 AC 125 ms
54,248 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 131 ms
56,052 KB
testcase_26 AC 133 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

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 int N = sc.nextInt();
		final long M = sc.nextLong();
		
		long other_fact = 1;
		for(int i = 1; i <= (N - 2); i++){
			other_fact *= i;
			other_fact %= MOD;
		}
		/*
		for(long i = M; i <= N; i += M){
			for(long j = M; j <= N; j += M){
				if(i == j || gcd(i, j) != M){ continue; }
				System.out.println(i + " " + j);
			}
		}
		//*/
		
		long[] pat = new long[N + 1];
		Arrays.fill(pat, N / M);
		if(M <= N){ pat[(int)(M)]--; }
		for(long i = 2 * M; i <= N; i += M){
			final long p = N / i;
			pat[(int)(i)] -= p;
			
			for(long j = 2 * i; j <= N; j += i){ 
				pat[(int)(j)] -= (p - 1);
				//System.out.println("> " + i + " " + j);
			}
		}
		
		long answer = 0;
		
		for(long fst = M; fst <= N; fst += M){
			//System.out.println(fst + " : " + pat[(int)(fst)]);
			answer += (pat[(int)(fst)] * other_fact) % MOD;
			answer %= MOD;
		}
		
		System.out.println(answer);
	}
}
0