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;
}
求特定倍数位数
本文介绍了一道算法题目,要求找到一个整数n的最小倍数,该倍数仅由数字1组成,并输出该倍数的位数。通过使用同余定理,文章提供了一种逐步累加并取模的方法来解决此问题。
5437

被折叠的 条评论
为什么被折叠?



