kattis ones简单题取模运算+枚举
生活随笔
收集整理的这篇文章主要介绍了
kattis ones简单题取模运算+枚举
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目链接原链接
题目
给定不被2和5整除的整数n,有些n的倍数是十进制中的1的序列(比如111,1111111).其中最小的一个1的序列是几位数字?
比如数字3的37倍是111.所以是三位
Given any integer 0≤n≤100000 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? There are at most 1000 test cases.
Sample Input 1
3
7
9901
Sample Output 1
3
6
12
解题思路
暴力枚举方法,需要考虑mod的性质。
既然要求1111111这样序列,我们就用这样序列来对n取余,从下往上枚举,如果为0,则这个就是最小的可行解。
代码
#include<bits/stdc++.h> using namespace std;int main() {int n;while(scanf("%d",&n)!=EOF){int number=1;int digit=1;while(number%n!=0)//取余为零退出 {number%=n;number=number*10+1;//从下往上遍历1,11,111, digit++;}cout<<digit<<endl;}return 0; }总结
以上是生活随笔为你收集整理的kattis ones简单题取模运算+枚举的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Leetcode402 remove-k
- 下一篇: Kattis-What does the