# Check if Decimal representation of given Binary String is divisible by K or not

Given a binary string S, the task is to find that the decimal representation of the given binary string is divisible by integer K or not.Examples:Input: S = 1010, k = 5Output: YesExplanation: Decimal representation of 1010 (=10) is divisible by 5Input: S = 1010, k = 6Output: NoApproach: Since the modulo operator is distributive over addition, the given binary string can be checked bit by bit to see whether the decimal % k is equal to zero or not. Follow the steps below for the approach:Initialize an array poweroftwo[], of size of binary string, to store the powers of two.Iterate till size and for each i store 2i % K in poweroftwo[].Initialize variables, say rem = 0, to store the current remaining number till i.Iterate till size and for each i and if S[size – i -1] is 1 then update rem equals rem + poweroftwo[i].Finally, return Yes if rem equals zero else return No.Below is the implementation of the above approach:C++#include using namespace std; string divisibleByk(string s, int n, int k){ int poweroftwo[n]; poweroftwo[0] = 1 % k; for (int i = 1; i < n; i++) { poweroftwo[i] = (poweroftwo[i - 1] * (2 % k)) % k; } int rem = 0; for (int i = 0; i < n; i++) { if (s[n - i - 1] == '1') { rem += (poweroftwo[i]); rem %= k; } } if (rem == 0) { return "Yes"; } else return "No";} int main(){ string s = "1010001"; int k = 9; int n = s.length(); cout