poj 2551 Ones(同余)

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 19:06   1808   0

Ones
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 11459 Accepted: 6487

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组成,并且输出最小的这个倍数的位数

思路:利用同余定理,边加1边取模即可,第一个模为0即是答案

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            sum=(sum*10+1)%n;
            if(!sum)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}




分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP