以3结尾的数字至少有一个具有全部的多个

Eul*_*ler 9 algorithm numbers

嗨这是Adobe面试中提出的问题.

Numbers ending in 3 have at least one multiple having all ones. 
for eg., 3 and 13 have amultiples like 111 and 111111 respectively. Given such 
a no. , find the smallest such multiple of that number. The multiple can 
exceed the range of int, long. You cannot use any complex data structure.
Run Code Online (Sandbox Code Playgroud)

你能为我提供一个有效的解决方案吗?

Eul*_*ler 14

得到了答案:)

int count=1, rem=1; 
while(rem)
{
 rem= (rem*10+1)%n; count++;
} 
 while(count--){ cout<<"1";}
Run Code Online (Sandbox Code Playgroud)

  • 你刚才说多重可能超过整数范围. (4认同)
  • 这是一个美丽的解决方案!能否详细说明它如何使用模运算? (3认同)