-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinary Modulo.java
More file actions
39 lines (33 loc) · 775 Bytes
/
Binary Modulo.java
File metadata and controls
39 lines (33 loc) · 775 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
//{ Driver Code Starts
//Initial Template for Java
import java.util.*;
import java.io.*;
import java.lang.*;
class GFG{
public static void main(String [] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
while(test-- > 0) {
String [] str = br.readLine().trim().split(" ");
String s = str[0];
int m = Integer.parseInt(str[1]);
Solution obj = new Solution();
System.out.println(obj.modulo(s,m));
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution{
int modulo(String s, int m) {
//Write your code here
int k=0;
char[] str=s.toCharArray();
for(char c:str)
{
int b=c-'0';
k=(k*2+b)%m;
}
return k;
}
}