思路:求base进制下,长度最短的数字满足乘以factor,使得原来的最低位等于最高位。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int base,first,factor; while(cin>>base>>first>>factor) { int now=first*factor; int ans=1; while(first!=now) { now=(now%base)*factor+now/base; ans++; } printf("%d ",ans); } return 0; }