试下,不知道对不对
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); sc.nextLine(); String s = sc.nextLine(); long[][] arr = new long[n + 1][k]; int c = Integer.valueOf(s.charAt(0)); arr[1][c % k] += 1; if (n <= 1){ System.out.println(arr[1][c % k]); return; } for (int i = 2;i <= n;i ++){ for (int j = 0;j < k;j ++){ int tmp = s.charAt(i - 1) - '0&(30533)#39; + j * 10; int yu = tmp % k; arr[i][yu] = (arr[i][yu] + arr[i - 1][j]) % 1000000007; } int yu = Integer.valueOf(s.charAt(i - 1)) % k; arr[i][yu] = (1 + arr[i][yu]) % 1000000007; for (int j = 0;j < k;j ++){ arr[i][j] += arr[i - 1][j]; } } long res = arr[n][0]; System.out.println(res); }