kattis ones简单题取模运算+枚举
生活随笔
收集整理的這篇文章主要介紹了
kattis ones简单题取模运算+枚举
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接原鏈接
題目
給定不被2和5整除的整數(shù)n,有些n的倍數(shù)是十進(jìn)制中的1的序列(比如111,1111111).其中最小的一個(gè)1的序列是幾位數(shù)字?
比如數(shù)字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的性質(zhì)。
既然要求1111111這樣序列,我們就用這樣序列來(lái)對(duì)n取余,從下往上枚舉,如果為0,則這個(gè)就是最小的可行解。
代碼
#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; }總結(jié)
以上是生活随笔為你收集整理的kattis ones简单题取模运算+枚举的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Leetcode402 remove-k
- 下一篇: Kattis-What does the