//http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1092&pid=7
//Problem H: 1的最少个数
#include<cmath> #include<cstring> #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int solve(int x) { if(x==0)return 0; int ans=1; int t=1; while(t%x) { ans++; t=(t%x)*10+1; if(ans>100000)return 0; } return ans; } int main() { int n; while(cin>>n) { int ans=solve(n); cout<<ans<<endl; } }
本文介绍了一个算法问题——求解对于给定整数n,需要多少个1串联起来才能被n整除。通过递增的方式找到满足条件的最小序列长度。此算法采用C++实现,并可通过输入不断获取新的测试案例。

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



