All the digits of the positive integer N are either 0 or 1 . The remainder after dividing N by 3 7 is 1 8 . What is the smallest number of times that the digit 1 can appear in N ?
Details and Assumptions :
This problem is not original.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
It is easier to translate this question to solving, over non-negative integers, for the minimum value of a + b + c given that 1 0 a + 2 6 b + c ≡ 1 8 ( m o d 3 7 ) .
The solution is a = 0 , b = 2 , c = 3 .
Log in to reply
I'm a bit confused, do you mean
a b c = 1 8 m o d 3 7
1 0 0 a + 1 0 b + c = 1 8 m o d 3 7
2 6 a + 1 0 b + c = 1 8 m o d 3 7 ?
Log in to reply
No. My approach is very different from yours. Note that your solution is incomplete because it has not established that 5 is indeed the minimum.
My solution: (Let me change my notation slightly)
Observe that
1
0
0
≡
1
,
1
0
1
≡
1
0
,
1
0
2
≡
2
6
,
1
0
3
≡
1
(
m
o
d
3
7
)
. Now, given any binary string S, let the number of 1's in the 0 mod 3 place be a, the number of 1's in the 1 mod 3 place be b, the number of 1's in the 2 mod 3 place be c. Then
S
≡
a
+
1
0
b
+
2
6
c
(
m
o
d
3
7
)
.
As such, your question translates to finding the minimum, over non-negative integers, of a + b + c , given that
2 6 a + 1 0 b + c ≡ 1 8 ( m o d 3 7 )
As mentioned, a = 2 , c = 3 is the minimum solution (which is easily checked). An example of S that this corresponds to is 1 1 0 1 1 0 1 .
Log in to reply
@Calvin Lin – Ok! Do you want to post this as a formal solution instead in the comment section? Else I feel like deleting my solution, as mentioned, it's badly organised...
This is only a first draft I've written during midnight. Please suggest edits.
It’s easier is you write 26a + 10b + c -11a + 10b + c 18 -19 mod 37
And then you see that a=2 and c=3 makes the sum = -19
Grrrrrrrrrrrreat problem @Christopher Boo
I did this : 37 * 18 = 666
666 in binary is : 1010011010
Minimum no. of 1s is : 5.
Simple. :)
import java.util.ArrayList;
public class BinaryLoop {
public static void main(String[] args) {
// TODO Auto-generated method stub
String num = "";
int counter = 0;
long count = 9223372036854775807L;
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i <= count; i++) {
String bin = Integer.toBinaryString(i);
if (bin.equalsIgnoreCase("10000000000000000000")) {
break;
} else {
long binit = Long.parseLong(bin);
if (checkMod(binit)) {
list.add(checkdig(binit));
}
}
int least = leastNum(list);
System.out.println(least);
}
}
public static boolean checkMod(long num) {
if (num % 37 == 18)
return true;
else
return false;
}
public static int checkdig(long num) {
int occurance = 0;
String number = num + "";
char[] digits = number.toCharArray();
for (int i = 0; i < digits.length; i++) {
if (digits[i] == '1') {
occurance++;
} else {
}
}
return occurance;
}
public static int leastNum(ArrayList<Integer> digit) {
int least = 1000000;
for (int i = 0; i < digit.size(); i++) {
if (least >= digit.get(i)) {
least = digit.get(i);
}
}
return least;
}
}
Here's my code for Python:
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 |
|
Here we can see from the Output when a=2, b=0, c=3 then we get minimum value = 5
// using c++ for help
bool check(int n)
{
int x;
while(n)
{
x=n%10;
if(x>1) return false;
n/=10;
}
return true;
}
int main( ) {
int n=18;
while(1)
{
if(check(n)) break;
n+=37;
}
cout<<n;
}
JavaScript for(var i =1;i<200;i++){ var b = (i).toString(2); var res1 = parseInt(b) % 37; if(res1 == 18) console.log("Great Number "+ b + " at "+i); }
Problem Loading...
Note Loading...
Set Loading...
EDIT: This solution is written with the help of Calvin Lin.
First, make sure you are familiar with the divisibility of 37 .
Did you noticed the trick? We can form a group of three and add it altogether.
Let a be the number of 1's added in the hundredths.
Let b be the number of 1's added in the tenths.
Let c be the number of 1's added in the ones.
Now, the question can be translated to, solve
1 0 0 a + 1 0 b + c ≡ 1 8 m o d 3 7
2 6 a + 1 0 b + c ≡ 1 8 m o d 3 7
over non-negative integers, for the minimum value of a + b + c .
By trial and error, we can easily get that a = 2 , b = 0 , c = 3 satisfy the condition and it's the minimum value of a + b + c . Hence, the answer is 5 .