Last active
August 29, 2015 14:19
-
-
Save mh-github/d36b285d4d17f5694c0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| import java.math.BigDecimal; | |
| import java.math.BigInteger; | |
| import java.util.ArrayList; | |
| public class n_multiple_Min_N_Zeros_Ones | |
| { | |
| private static int NUM = 2000; | |
| public static void main(String args[]) { | |
| long pow[] = new long[NUM], val[] = new long[NUM], x, num, ten; | |
| int i, j, count; | |
| for (num = 2; num < NUM; num++) { | |
| for (i = 0; i < NUM; pow[i++] = 0) | |
| ; | |
| count = 0; | |
| for (ten = 1, x = 1; x < NUM; x++) { | |
| val[(int) x] = ten; | |
| for (j = 0; j < NUM; j++) | |
| if (pow[j] != 0 && pow[(int) ((j + ten) % num)] == 0 && pow[j] != x) | |
| pow[(int) ((j + ten) % num)] = x; | |
| if (pow[(int) ten] == 0) | |
| pow[(int) ten] = x; | |
| ten = (10 * ten) % num; | |
| if (pow[0] != 0) | |
| break; | |
| } | |
| x = num; | |
| System.out.format("%d\tdivides\t", x = num); | |
| if (pow[0] != 0) { | |
| while (x != 0) { | |
| while (--count > pow[(int) (x % num)] - 1) | |
| System.out.format("0"); | |
| count = (int) (pow[(int) (x % num)] - 1); | |
| System.out.format("1"); | |
| x = (num + x - val[(int) pow[(int) (x % num)]]) % num; | |
| } | |
| while (count-- > 0) | |
| System.out.format("0"); | |
| } else { | |
| System.out.format("Can't do it!"); | |
| } | |
| System.out.format("\n"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment