首页 > 其他 > 详细

POJ2551 Ones

时间:2015-03-21 21:09:45      阅读:310      评论:0      收藏:0      [点我收藏+]
简单暴力会超时,稍微动脑筋优化一下即可

其实根据(a+b)%d=(a%d+b%d)%d就可以做出来了。

以7为例

1%7=1              1%7=1

11%7=4          (10%7+1)%7=4

111%7=6        (4*10%7+1)%7=6

1111%7=5      (6*10%7+1)%7=5

11111%7=2     (5*10%7+1)%7=2

111111%7=0   (2*10%7+1)%7=0

输出6.

 
Ones
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10892   Accepted: 6193

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

Source

 
技术分享
 1 //oimonster
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<iostream>
 5 using namespace std;
 6 int main(){
 7     int i,j,n;
 8     bool f;
 9     int s,t=0;
10     while(scanf("%d",&n)!=EOF){
11         f=false;
12         t=s=1;
13         t=t%n;
14         while(t!=0){
15             t=(t*10%n+1)%n;
16             s++;
17         }
18         printf("%d\n",s);
19     }
20     return 0;
21 }
View Code

 

POJ2551 Ones

原文:http://www.cnblogs.com/oimonster/p/4356109.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!