| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么SPJ过不了?答案应该是正确的所有的情况都验证过了,为什么始终报WA? 我的程序输出是: n m --------------------------- 1 1 2 10 3 111 4 100 5 10 6 1110 7 1001 8 1000 9 111111111 10 10 11 11 12 11100 13 1001 14 10010 15 1110 16 10000 17 11101 18 1111111110 19 11001 20 100 21 10101 22 110 23 110101 24 111000 25 100 26 10010 27 1101111111 28 100100 29 1101101 30 1110 31 111011 32 100000 33 111111 34 111010 35 10010 36 11111111100 37 111 38 110010 39 10101 40 1000 41 11111 42 101010 43 1101101 44 1100 45 1111111110 46 1101010 47 10011 48 1110000 49 1100001 50 100 51 100011 52 100100 53 100011 54 11011111110 55 110 56 1001000 57 11001 58 11011010 59 11011111 60 11100 61 100101 62 1110110 63 1111011111 64 1000000 65 10010 66 1111110 67 1101011 68 1110100 69 10000101 70 10010 71 10011 72 111111111000 73 10001 74 1110 75 11100 76 1100100 77 1001 78 101010 79 10010011 80 10000 81 1111111101 82 111110 83 101011 84 1010100 85 111010 86 11011010 87 11010111 88 11000 89 11010101 90 1111111110 91 1001 92 11010100 93 10000011 94 100110 95 110010 96 11100000 97 11100001 98 11000010 99 111111111111111111 100 100 101 101 102 1000110 103 11100001 104 1001000 105 101010 106 1000110 107 100010011 108 110111111100 109 1001010111 110 110 111 111 112 10010000 113 1011011 114 110010 115 1101010 116 110110100 117 11101110111 118 110111110 119 100111011 120 111000 121 11011 122 1001010 123 111111111111111 124 11101100 125 1000 126 11110111110 127 11010011 128 10000000 129 100100001 130 10010 131 101001 132 11111100 133 11101111 134 11010110 135 11011111110 136 11101000 137 10001 138 100001010 139 110110101 140 100100 141 10011 142 100110 143 1001 144 1111111110000 145 11011010 146 100010 147 1100001 148 11100 149 110111 150 11100 151 1110001 152 11001000 153 111111111000000000000000111111111 154 10010 155 1110110 156 1010100 157 1000000000000000000000000000000000000001 158 100100110 159 100011 160 100000 161 11101111 162 11111111010 163 1010111 164 1111100 165 1111110 166 1010110 167 11111011 168 10101000 169 10111101 170 111010 171 1111011111 172 110110100 173 1011001101 174 110101110 175 100100 176 110000 177 100101111 178 110101010 179 11010111 180 11111111100 181 1001111 182 10010 183 100101 184 110101000 185 1110 186 100000110 187 1001011 188 1001100 189 1101111111000001101111111 190 110010 191 11101111 192 111000000 193 11001 194 111000010 195 101010 196 110000100 197 1101000101 198 1111111111111111110 199 111000011 200 1000 ------------------------------- 附程序(Java) import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigInteger; public class Main { @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { InputStream input = null; input = System.in; BufferedReader stdin = new BufferedReader(new InputStreamReader(input)); StringBuffer sb = new StringBuffer(); String line = stdin.readLine(); while (line != null && !"0".equals(line)) { int n = Integer.valueOf(line); BigInteger t = f(n); sb.append(t.toString()).append("\n"); line = stdin.readLine(); } System.out.println(sb); } /** * 返回形如A*(10^m-1)/(10^k-1)的位数不超过100的n的倍数。 * 其中A各位都是0,1且不超过k位数,m是k的倍数。 * @param n * @return */ private static BigInteger f(int n) { int pow2 = 0; while (n%2 == 0) { pow2 ++; n /= 2; } int pow5 = 0; while (n%5 == 0) { pow5 ++; n /= 5; } int p = Math.max(pow2, pow5); int d = d(n); BigInteger N = BigInteger.valueOf(n); int t = 1; while (t < 200/d+1) { int w = d*t; BigInteger x = BigInteger.TEN.pow(w).subtract(BigInteger.ONE); for (int k = w; k > 0; k --) { if (w%k == 0) { for (int a = 1; a < Math.pow(2, Math.min(10, k)); a ++) { BigInteger A = new BigInteger(Integer.toBinaryString(a)); BigInteger y = BigInteger.TEN.pow(k).subtract(BigInteger.ONE); BigInteger z = x.divide(y).multiply(A); if (z.mod(N).compareTo(BigInteger.ZERO) == 0) { z = z.multiply(BigInteger.TEN.pow(p)); if (z.toString().length() < 100) { return z; } } } } } t ++; } return BigInteger.valueOf(-1); } private static int[] ps = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199 }; private static int phi(int n) { int m = n; for (int i = 0; i < ps.length; i ++) { if (n%ps[i] == 0) m = m/ps[i]*(ps[i]-1); } return m; } private static int d(int n) { int m = phi(n); BigInteger N = BigInteger.valueOf(n); for (int i = 1; i <= m; i ++) { if (m%i == 0) { BigInteger w = BigInteger.TEN.pow(i).subtract(BigInteger.ONE); if (w.mod(N).compareTo(BigInteger.ZERO) == 0) { return i; } } } return -1; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator