poj-2551-ones

简介: Description Given any integer 0

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,求出不能整除3和5,却能整除d并且这个数各位都是1;
111111111111%9901==0;
#include <iostream>
#include <cstdio>

using namespace std;


int main()
{
    int n;

    while(~scanf("%d",&n))//EOF
    {
        int cnt=1;
        int num=1;

        while(num%n)
        {
            num=(num*10+1)%n;//直接找由1构成的数,判断是不是n的倍数
            cnt++;
        }
        printf("%d\n",cnt);
    }

    return 0;
}

  

相关文章
|
9月前
|
算法 数据建模
Poj 3169(差分约束系统)
Poj 3169(差分约束系统)
39 0
|
人工智能 机器学习/深度学习
|
人工智能 算法 BI
poj 2192 Zipper
题目链接:http://poj.org/problem?id=2192 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18658   Accepted: 6651 Description Given ...
987 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
851 0
poj 3620
题意:给出一个矩阵,其中有些格子干燥、有些潮湿。       如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大       的湖泊,求最大的湖泊。       也就是求出最大的连在一块儿的潮湿的格子的数目。
584 0
POJ 2027 No Brainer
Problem Description Zombies love to eat brains. Yum. Input The first line contains a single integer n indicating the number of data sets.
874 0
|
算法 计算机视觉
最小割-poj-2914
poj-2914-Minimum Cut Description Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must b
1574 0