CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;
int divisible(string s, int k){
int cnt=0;
int *arr=new int[k];
arr[0]=1;
string str="";
for(int i=s.length()-1; i>=0;i--){
str = s[i]+str;
int n=stoi(str);
cnt += arr[n%k];
arr[n%k]++;
}
return cnt;
}
int main() {
string s="334455";
int k=11;
cout<<divisible(s, k);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run