博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2551
阅读量:7165 次
发布时间:2019-06-29

本文共 616 字,大约阅读时间需要 2 分钟。

题意:n<=10000,并保证存在n的某个倍数的十进制表示形式各个数位都为1。问这个数是n的多少倍。

分析:我们枚举1,11,111……直到找到能被n整除的为止。为了防止这个1序列过大,我们不断将其对n取余,这样可以保证其一直在int范围内,并且不影响整除性。

#include 
#include
#include
#include
using namespace std;int n;int main(){ while (scanf("%d", &n) != EOF) { int ans = 1; int temp = 1; while (temp) { ans++; temp = temp * 10 + 1; temp %= n; } printf("%d\n", ans); } return 0;}
View Code

 

转载于:https://www.cnblogs.com/rainydays/archive/2013/06/07/3124054.html

你可能感兴趣的文章