結果

問題 No.2032 Let's Write Multiples!!
ユーザー ShirotsumeShirotsume
提出日時 2022-07-15 02:46:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,643 ms / 3,000 ms
コード長 1,161 bytes
コンパイル時間 2,275 ms
コンパイル使用メモリ 74,228 KB
実行使用メモリ 70,668 KB
最終ジャッジ日時 2023-09-09 03:41:07
合計ジャッジ時間 37,158 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,476 KB
testcase_01 AC 1,180 ms
65,564 KB
testcase_02 AC 1,115 ms
69,560 KB
testcase_03 AC 1,039 ms
70,240 KB
testcase_04 AC 1,362 ms
66,836 KB
testcase_05 AC 1,628 ms
65,988 KB
testcase_06 AC 1,551 ms
68,096 KB
testcase_07 AC 1,231 ms
65,808 KB
testcase_08 AC 1,378 ms
65,168 KB
testcase_09 AC 1,627 ms
66,564 KB
testcase_10 AC 1,446 ms
68,388 KB
testcase_11 AC 1,429 ms
67,996 KB
testcase_12 AC 1,446 ms
68,452 KB
testcase_13 AC 1,411 ms
66,668 KB
testcase_14 AC 1,361 ms
65,684 KB
testcase_15 AC 1,340 ms
70,668 KB
testcase_16 AC 1,365 ms
66,820 KB
testcase_17 AC 1,347 ms
70,660 KB
testcase_18 AC 1,643 ms
69,504 KB
testcase_19 AC 1,369 ms
67,388 KB
testcase_20 AC 1,166 ms
67,220 KB
testcase_21 AC 1,179 ms
65,264 KB
testcase_22 AC 1,176 ms
70,048 KB
testcase_23 AC 1,190 ms
68,904 KB
testcase_24 AC 1,200 ms
67,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int t = sc.nextInt();
	        for(int i = 0; i < t; i++){
                long l = sc.nextLong();
                long r = sc.nextLong();
                long k = sc.nextLong();
                long c = sc.nextLong();
                long ans = f(r, k, c) - f(l - 1, k, c);
                System.out.println(ans);
	        }
	    }
	public static long floorSum(long n, long m, long a, long b){
		  long ret = 0;
		  if(a >= m){
			  ret += (n - 1) * n * (a/m)/2;
			  a %= m;
		  }
		  if(b >= m){
			  ret += n * (b/m);
			  b %= m;
		  }
		  long ym = (a * n + b) / m;
		  long xm = (ym * m - b);
		  if(ym == 0) return ret;
		  ret += (n - (xm + a - 1)/a) * ym;
		  ret += floorSum(ym, a, m, (a - xm % a) % a);
		  return ret;
	  	}
	
	public static long f(long r, long k, long c){
		long n = r / k;
		long ans = 0;
		long d = 1;
		for(int i = 0; i < 9; i++){
			long x = c * d;
			long y = (c + 1) * d;
			d *= 10;
			ans += floorSum(n, d, k,  d + k - x) - floorSum(n, d, k,  d + k - y);
		}
		return ans;
	}


}
0