H - Ones
Description
Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?
Input
Each line contains a number n.
Output
Output the number of digits.
Sample Input
3 7 9901
Sample Output
3 6 12
这个题!!!实在是看不懂它到底在说什么!!!英语太差没办法 忧愁!!!
去网上搜来了翻译
绐任一个整数 n(1 <= n <= 9999),且 n 不可被 2 或 5 除尽。n的某一个倍数以十进制的表示法将是一连串的1,请问这一连串的1最少是几位数?
例如:
n=3,3*37=111,所以答案是3位数。
n=7,7*15873=111111,所以答案是6位数。
Input
每一列测试资料有1个整数 n
Output
对每一测试资料n,其某一个倍数以十进制的表示法将是一连串的1,请问这一连串的1最少是几位数?
看完翻译,题目确实不难。
以下为第一次写出的超时代码
#include <iostream> using namespace std; int main() { int n; while(cin>>n){ __int64 a=1,i=1; while(a%n!=0){ a=a*10+1; i++; } cout<<i<<endl; } //system("pause"); return 0; }
以下为正确代码,有一定的技巧性
#include<iostream> using namespace std; int f(int n) { int i=1,a,b=1; a=b%n; while(a!=0) { b=a*10+1; i++; a=b%n; } return i; } int main() { int n; while(cin>>n)cout<<f(n)<<endl; return 0; }
拿3来解释
1%3=1,先将其乘3加1,直到得到的值大于3. 11%3=2 , 2×10+1=21 则21/3与111/3效果相同 (因为90%3=0,111-90=21 )
要多思考 数学简便方法!!!
Hint
RunID | User | ProblemA - 487-3279 | Result All | Memory (KB) | Time (ms) | Language All | Length (Bytes) | Submit Time |
---|
1
26
32963
47:31:36 (-2)
48:03:47
40:57:20
31:23:27
41:23:55 (-4)
42:00:19
44:00:07
32:38:31 (-3)
31:44:21
30:43:47
20:02:54
9:19:12 (-1)
42:59:04
3:43:57 (-1)
3:55:20
4:21:02 (-1)
4:29:24
5:02:56 (-6)
6:36:08
6:43:44 (-1)
6:47:57
8:39:04
6:56:08
7:12:35 (-1)
7:14:13
8:12:57
2
26
67575
69:18:44 (-2)
69:02:25 (-2)
54:06:56
49:20:56
49:08:05 (-1)
48:55:00
54:46:12 (-3)
55:24:31 (-1)
48:25:33
48:05:56
47:38:16 (-3)
47:08:10 (-5)
68:12:17
34:32:33 (-1)
34:22:20
34:14:58
34:09:05
33:58:24
33:43:29
33:08:58
32:57:04
32:50:16
26:58:50
26:42:08
26:25:35
26:18:39 (-1)
3
26
118911
68:06:43
170:01:48
169:14:16
167:22:08
57:14:03
166:08:42 (-3)
168:44:59
52:28:58
93:48:21 (-4)
76:28:17 (-1)
77:48:18 (-4)
58:14:36 (-5)
75:45:37 (-1)
9:11:08 (-1)
9:23:49
9:45:56
44:41:32
10:03:30
44:13:40 (-1)
31:15:43 (-2)
30:53:05
167:48:10 (-1)
44:29:06 (-1)
31:01:19 (-1)
45:13:42 (-2)
93:04:07 (-1)
4
26
126009
204:39:05
202:32:19
154:52:39
153:23:29
123:52:11 (-2)
124:10:51
202:22:21
126:10:14 (-1)
125:11:43
75:20:46
77:34:34
75:07:17
49:46:18 (-1)
4:56:58
4:57:52 (-3)
6:20:52 (-4)
32:57:44
33:23:44
33:48:47
34:31:28
34:46:16
42:12:13 (-1)
42:34:00
42:46:00
43:03:03
44:06:50 (-2)
5
26
208294
286:40:54 (-44)
286:52:49 (-3)
219:38:31 (-1)
153:40:23 (-1)
219:04:47 (-1)
153:32:58 (-2)
216:19:40 (-13)
153:00:58 (-1)
152:38:15
149:15:47 (-2)
149:30:11
148:06:38 (-4)
148:53:36
77:30:59
77:31:56
77:32:49
77:33:46
77:34:48
77:35:36
77:36:29
77:37:05
77:37:33
77:39:10
77:39:39
77:40:33
78:49:05 (-1)
6
26
244382
148:39:32 (-2)
202:38:07 (-3)
179:19:28 (-1)
176:19:01
165:47:55 (-4)
178:50:46 (-2)
177:44:07
175:40:26 (-1)
174:50:44
173:49:26 (-1)
171:26:51 (-3)
171:50:33
166:54:41
127:48:50 (-2)
130:38:27
131:10:17 (-5)
131:15:52
141:26:23
141:36:32 (-1)
141:43:14
141:48:36
141:54:35
142:13:59
142:28:21
142:36:42
144:09:15
7
26
271500
194:41:47
246:21:55
263:36:45
176:06:38 (-2)
175:32:08
175:16:12 (-3)
334:25:02 (-3)
127:58:53 (-1)
189:04:15 (-1)
189:17:29
192:52:54
125:04:28 (-2)
193:23:49 (-1)
123:53:05 (-6)
125:36:24
126:03:20 (-1)
126:12:37
126:32:11
169:16:53 (-2)
127:13:19 (-3)
145:37:44 (-3)
169:22:09
168:53:08
166:36:54 (-1)
165:44:25
189:35:45 (-3)
8
26
282038
342:56:33
335:23:21
316:46:41
288:11:45
317:13:07
165:44:56 (-1)
334:41:08 (-2)
296:53:37
217:32:44
128:37:00
286:45:03 (-1)
215:10:54 (-5)
287:39:09
50:56:41 (-6)
58:04:47
58:22:15 (-2)
78:43:47
78:36:04 (-1)
104:32:49 (-2)
105:41:25 (-3)
77:26:04 (-4)
153:19:21 (-2)
79:21:45
78:57:43
79:51:39
152:28:21 (-3)
9
26
318221
175:12:35 (-16)
318:24:39 (-2)
335:50:15 (-3)
336:02:39
336:35:32
356:49:02 (-1)
358:03:02 (-9)
358:11:51
358:34:34 (-3)
380:22:47 (-2)
381:26:03 (-3)
382:27:15 (-1)
433:22:47
49:31:09 (-2)
49:46:29
50:06:29
50:15:15
50:35:53
51:11:17 (-1)
51:25:32 (-1)
51:33:50
72:08:35 (-6)
72:55:41 (-2)
73:20:59
74:10:44 (-7)
74:56:47 (-2)
10
26
326975
151:58:33
153:29:25
172:35:23
172:41:52
189:57:24 (-2)
190:01:19
190:15:02 (-2)
193:03:03
193:07:48
193:13:05
193:20:31
193:35:12
193:52:06
196:49:30
196:50:39
197:01:19 (-5)
197:25:12
197:26:26
197:29:28
268:44:46
268:45:58
268:47:04
268:53:05
268:57:14
268:59:02
269:15:01
11
26
336691
358:50:56 (-8)
342:31:11 (-9)
261:47:52
340:47:49 (-2)
251:05:27
249:54:46
339:41:33 (-9)
286:29:55 (-7)
246:11:41
245:52:05 (-2)
240:19:19 (-5)
189:15:09 (-3)
177:31:01
150:27:16 (-1)
150:49:36
151:19:35 (-1)
151:30:11
152:18:15 (-2)
152:56:35
153:14:38
153:20:25
166:06:10 (-2)
166:26:56 (-1)
166:58:20
172:00:12
175:04:11 (-4)
12
26
344616
189:25:01 (-5)
194:29:25 (-6)
195:32:42
197:41:24
218:28:42 (-6)
219:02:29
223:23:43 (-3)
365:06:04 (-21)
223:50:48
224:04:45
227:08:02 (-6)
224:57:01 (-1)
226:22:28
212:47:31
212:58:03
213:14:20
213:22:19
213:30:33
214:06:08 (-3)
214:15:54
214:24:10
216:11:15 (-1)
216:40:19 (-3)
216:56:22
217:05:54
218:11:35 (-6)
13
26
424448
379:55:18 (-4)
358:28:57 (-2)
361:48:04
289:05:30
289:59:23 (-1)
286:27:44
288:45:01
288:04:26 (-1)
261:22:15 (-2)
261:47:57 (-1)
381:06:03 (-4)
334:17:43 (-4)
240:53:54
238:07:23 (-12)
188:32:14
188:53:57
238:23:22
238:42:22
239:42:54 (-2)
238:32:31 (-4)
189:20:26
219:30:00
239:58:50
240:19:30
240:29:35
338:13:38 (-3)
14
25
211941
356:53:14 (-1)
239:04:56
250:48:51 (-1)
339:45:59
268:06:25
358:13:43
333:16:04
98:05:31
95:21:35
97:11:19
94:18:09
93:26:34
53:04:59
68:22:16
68:08:48
68:34:53
70:24:10
69:53:59
71:03:12
69:00:44 (-1)
71:58:13
71:23:55
73:12:01
73:34:35
78:07:50
15
25
406364
344:52:17 (-27)
272:59:59
272:11:33
319:27:20
318:59:54 (-3)
338:35:14
310:28:30 (-3)
310:53:06
272:33:57
313:30:11
219:36:52 (-5)
313:01:27
217:40:28 (-2)
219:50:28
220:15:27 (-1)
225:50:49
226:00:47
237:58:10 (-2)
238:14:02
238:27:08 (-1)
240:15:10 (-3)
240:26:46 (-2)
241:00:11 (-2)
241:40:57
360:34:08 (-1)
16
24
256686
173:51:03 (-13)
174:35:07 (-2)
174:44:20
315:46:32 (-2)
269:02:06 (-4)
318:21:14 (-2)
237:25:40
268:55:22
236:32:22
267:12:38 (-5)
317:41:14 (-1)
105:31:29 (-8)
96:04:38
125:52:08 (-1)
125:43:45 (-1)
105:03:14 (-1)
126:28:35 (-1)
125:30:18 (-3)
95:48:22
116:26:12 (-1)
117:07:19 (-1)
117:22:49 (-3)
125:04:51
124:35:15 (-3)
17
24
329051
292:46:14 (-10)
(-13)
459:42:32
243:41:46 (-3)
458:18:10 (-1)
457:36:35 (-1)
289:15:56 (-6)
246:12:06
241:31:02 (-2)
245:47:52 (-3)
244:10:41 (-2)
243:39:33 (-2)
141:07:03
141:19:54
141:53:18 (-2)
142:00:51
142:23:34
143:25:27
143:36:08
143:57:15
144:23:00 (-1)
6:38:31 (-4)
148:58:37
149:09:28
459:16:15 (-3)
18
24
355453
291:31:26 (-4)
241:22:46
262:17:37 (-4)
268:26:20 (-1)
291:04:05 (-2)
290:04:03 (-8)
251:32:28 (-2)
267:56:05 (-4)
267:13:00 (-6)
250:49:55 (-3)
264:01:40
246:47:48
146:08:24 (-2)
170:23:58 (-2)
245:52:47
246:59:58 (-1)
286:25:15
197:57:47 (-6)
170:38:36
248:50:50 (-6)
242:15:05 (-2)
244:00:42 (-3)
245:44:08 (-2)
266:08:22 (-1)
19
24
426894
(-14)
387:38:41
388:50:22 (-3)
389:06:44
296:34:12 (-4)
409:42:35 (-6)
312:03:45 (-2)
251:54:37
299:44:40 (-3)
408:22:07
228:04:47 (-7)
222:25:27
298:40:47
262:41:19 (-1)
290:15:35 (-4)
251:21:25
265:57:01 (-5)
267:25:31 (-2)
268:57:28 (-2)
266:33:47
250:59:07 (-2)
269:21:56 (-2)
270:00:48
270:26:38
272:25:24 (-3)
20
24
506087
(-1)
387:18:48
386:43:55
386:41:27 (-3)
386:16:20
385:19:59
383:13:13
365:18:14
369:38:41
372:04:34
372:22:56 (-1)
383:02:23 (-1)
316:16:28
316:16:39
316:48:01
317:18:14
318:06:29
320:04:00
321:54:00 (-1)
322:16:52
322:22:42
344:33:52 (-3)
345:04:23 (-1)
345:36:55
346:08:22 (-2)
21
21
451903
332:59:02 (-5)
364:50:52
430:22:50
411:59:04 (-1)
320:04:21 (-2)
333:54:55
457:34:38 (-1)
429:25:50 (-4)
201:18:54 (-2)
334:31:11 (-1)
363:49:28 (-1)
334:03:09 (-1)
406:43:32 (-4)
343:34:36
344:06:09 (-1)
340:27:06
341:17:19
340:40:27
335:05:07 (-2)
340:20:12
413:35:14 (-8)
22
20
220064
(-3)
250:20:40
(-3)
247:32:33
205:39:54 (-3)
(-29)
150:02:50 (-1)
202:34:58
202:02:58
200:27:09 (-2)
(-1)
149:20:23 (-2)
151:18:35
152:19:27 (-1)
152:38:42 (-1)
153:16:17
175:36:59 (-2)
176:12:42
176:27:54
176:59:08 (-1)
178:29:56 (-3)
178:56:55
179:10:56
201:15:29 (-5)
23
20
317691
(-1)
261:45:50
317:33:27
312:57:09 (-8)
246:02:53
246:51:09
286:19:47 (-1)
245:41:50 (-1)
237:05:53 (-3)
213:47:44
244:23:58 (-2)
213:02:45 (-2)
214:37:48
356:40:09
238:48:28
218:59:08
218:11:33 (-1)
237:47:42
287:07:29 (-2)
333:39:13
356:47:15
24
19
426398
(-4)
458:50:22
440:16:44 (-1)
439:49:44 (-3)
438:41:21 (-3)
436:43:09 (-1)
436:05:51
249:39:14 (-1)
295:47:39 (-1)
297:52:16 (-4)
296:24:38
298:44:03 (-4)
299:01:42 (-1)
322:48:28
322:54:31
415:07:12 (-1)
409:58:13
412:26:50 (-2)
412:36:38
414:50:14 (-2)
25
18
297751
411:01:08 (-8)
261:45:27 (-3)
(-1)
434:19:13 (-7)
387:59:04 (-5)
387:00:08
202:01:11 (-6)
195:44:27 (-2)
196:19:27 (-2)
197:43:05
197:33:57
262:20:04 (-9)
201:56:13 (-2)
202:10:46
316:34:11
218:15:48 (-3)
218:54:19 (-3)
265:13:48
385:19:03 (-11)
26
17
123766
(-1)
(-3)
122:10:36 (-4)
123:38:59
125:20:05 (-3)
126:47:22 (-4)
120:02:39 (-2)
78:57:45 (-1)
79:25:53
126:11:51
127:03:15
127:07:30
127:22:27
127:42:06
128:57:29
129:07:04
129:10:56
129:14:03
(-1)
129:26:01 (-1)
27
17
270624
367:59:58 (-6)
(-3)
246:54:25
(-1)
392:07:59
368:33:13 (-1)
102:47:23 (-4)
79:12:36 (-1)
79:36:56 (-3)
175:18:52
176:04:40 (-4)
391:14:27 (-4)
391:18:30 (-3)
246:35:54 (-4)
103:24:52 (-3)
391:02:26 (-4)
390:57:50 (-4)
271:52:27 (-1)
320:22:25 (-3)
28
17
274463
434:38:48 (-5)
435:54:17
(-2)
457:30:49
248:48:18
441:58:27
192:35:31 (-2)
193:03:58
202:00:21 (-1)
202:12:16
202:35:44
203:09:54
219:16:40
219:36:03
220:21:10 (-1)
225:48:21
226:19:05
245:14:06 (-1)
29
16
156529
190:05:02 (-1)
195:48:59
203:00:37 (-4)
197:36:18 (-2)
140:59:30 (-3)
86:20:05
151:57:22
152:44:59
168:56:42
123:25:29 (-1)
169:36:32
117:08:15 (-1)
181:33:03
174:16:21
169:59:17 (-1)
181:00:29
30
15
202376
(-5)
272:26:22
273:00:11 (-1)
244:39:01 (-2)
201:53:20 (-1)
202:02:38
202:17:16
202:25:20
202:36:53
215:04:47 (-1)
214:42:52
215:10:14
215:59:49
220:27:38
244:11:33
244:18:28
31
14
349335
363:05:10 (-3)
392:53:56 (-3)
393:25:56
393:12:24
393:34:32 (-1)
405:03:39 (-2)
431:10:50 (-1)
433:24:32
433:35:35
434:15:57
434:28:24
434:40:21
435:23:36
440:20:35 (-1)
32
14
351728
310:37:51 (-10)
453:22:11
357:16:54
362:26:56 (-4)
358:49:18 (-2)
433:38:02 (-2)
434:03:05
436:17:24 (-2)
436:15:08
455:00:45 (-1)
453:31:42
453:42:17 (-2)
454:12:16
454:54:52 (-1)
33
13
133192
58:55:57 (-1)
59:13:51
59:29:33
59:36:17
60:20:47 (-3)
250:22:36 (-2)
250:49:44
251:58:52
269:32:26
270:17:40
271:19:41
271:38:23
81:56:28 (-7)
34
13
170957
267:02:03
199:31:16 (-2)
201:58:22 (-1)
202:21:21 (-2)
202:39:35
202:57:37
213:41:33 (-3)
214:53:36 (-1)
219:07:30
219:34:12 (-1)
220:32:17 (-4)
238:12:59 (-1)
241:24:50 (-1)
35
13
197451
222:07:39 (-2)
222:29:13 (-1)
222:38:57
222:50:20
222:56:41
223:15:39
223:25:01
287:03:06
287:21:32 (-1)
287:39:34
288:07:50 (-2)
288:21:17
289:34:48 (-3)
36
12
44113
61:27:07
61:01:34
61:02:30
61:04:12
61:12:34
61:10:02 (-1)
(-1)
61:16:53
61:18:04
61:08:00
61:26:37
61:25:22
61:21:02
37
11
214461
(-1)
414:13:39 (-2)
392:53:18 (-1)
223:22:41
223:49:29
224:13:49
414:30:21 (-2)
404:59:16 (-4)
235:36:36 (-1)
407:21:14 (-2)
392:17:40 (-2)
236:23:55
38
11
222725
(-3)
318:11:47
334:15:17 (-2)
333:43:39
340:14:46
334:24:28
339:55:59
340:30:43 (-1)
(-6)
341:41:05
342:10:18
342:27:53 (-1)
342:49:40 (-1)
39
11
273384
(-12)
383:04:30 (-1)
(-3)
(-2)
414:00:49
366:10:29
410:34:35 (-5)
433:35:56
412:40:21
434:47:35 (-1)
433:46:51
(-8)
435:16:42
412:23:49 (-12)
413:42:57
40
10
122044
267:17:44 (-3)
313:35:57
117:03:12 (-3)
313:36:38
168:43:56 (-9)
169:02:11
169:12:53 (-1)
169:38:44 (-1)
169:18:17
170:15:05 (-2)
41
9
138572
252:21:04 (-1)
300:08:22 (-4)
179:51:14
227:51:52
(-2)
317:47:45 (-3)
297:33:31
228:10:43 (-1)
251:36:01
251:12:12
42
9
218079
433:31:24 (-1)
240:54:46
408:02:00 (-1)
408:21:33 (-1)
409:21:17
(-4)
(-11)
431:11:14 (-1)
432:22:32 (-9)
432:58:44
433:15:51 (-1)
43
9
237495
411:47:10
432:39:44 (-1)
433:13:34
433:28:53
433:50:26
434:02:39
(-2)
459:39:12 (-2)
459:11:27 (-1)
459:02:20
44
8
99634
105:10:51 (-4)
167:14:41 (-4)
168:38:37 (-2)
169:11:39
172:29:48
223:09:31 (-2)
309:58:26 (-2)
340:01:11
(-1)
45
8
151866
(-2)
313:34:40
313:46:20 (-1)
314:00:00
316:23:57 (-2)
317:12:40 (-2)
317:23:16 (-1)
317:37:42
318:27:47 (-2)
46
8
212803
416:16:34 (-2)
432:12:38 (-1)
438:00:38
438:18:36
443:32:20 (-2)
457:57:21 (-1)
458:37:08 (-2)
459:08:14
47
7
27866
3:33:31
168:41:49 (-1)
168:49:54
31:18:19
30:42:58
30:31:23
30:28:14
48
7
186183
434:45:23
436:07:54
440:21:57 (-4)
437:40:13
438:04:39 (-1)
456:48:23 (-2)
456:54:55
49
6
95405
(-6)
236:42:18 (-1)
237:25:17
268:34:37 (-5)
236:31:04 (-1)
388:49:55 (-1)
(-2)
218:02:34 (-4)
50
6
140852
(-39)
340:08:40 (-6)
342:43:03
358:43:25
429:49:28 (-4)
459:42:30
411:45:18 (-4)
51
5
41185
(-1)
98:48:22 (-1)
121:08:42 (-7)
121:49:57 (-1)
122:20:26
(-3)
216:57:41 (-7)
(-5)
(-4)
(-2)
(-3)
(-1)
52
5
89765
(-30)
(-2)
201:44:51 (-1)
368:11:08 (-6)
369:07:21 (-4)
369:30:21 (-4)
179:31:29 (-9)
936/2552 36%
![](http://acm.hust.edu.cn/vjudge/images/loader.gif)
![Find me](http://acm.hust.edu.cn/vjudge/images/find_me.png)
![Go to top](http://acm.hust.edu.cn/vjudge/images/go_top.png)
![Rank config](http://acm.hust.edu.cn/vjudge/images/config.png)