日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

kattis ones简单题取模运算+枚举

發布時間:2025/4/5 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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简单题取模运算+枚举的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。