結果

問題 No.644 G L C C D M
ユーザー uafr_cs
提出日時 2018-02-02 22:41:32
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 56,508 KB
最終ジャッジ日時 2024-12-31 07:55:55
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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;
		
		int c = 0;
		for(long fst = M; fst <= N; fst += M, c++){
			if(fst == M){
				final long count = (N / M);
				final long two_count = (count * (count - 1)) % MOD;
				
				answer += (two_count * other_fact) % MOD;
				answer %= MOD;
			}else{
				final long count = (((N / M) - c) - (N / fst));
				final long two_count = (count * (count - 1)) % MOD;
				
				answer += (two_count * other_fact) % MOD;
				answer %= MOD;
			}
		}
		
		System.out.println(answer);
	}
}
0