已知a/b,求c的位置

现有一式子 a / b. 你需要找出数字 c 在小数点后第一次出现的位置

Input

输入包含三个整数 abc (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).

Output

输出数字 c 第一次在小数点后出现的位置,如果 c 不在小数点后出现输出 -1

Sample Input

Input
1 2 0
Output
2
Input
2 3 7
Output
-1

Sample Output

Hint

第一组样例 : 1 / 2 = 0.5000(0) 出现在第二个位置

第二组样例 : 2 /3 = 0.6666(6) 7 没有出现,输出 -1

扫描二维码关注公众号,回复: 2203250 查看本文章
思路: 其实思路挺简单,但是没想明白,这道题其实运用了传统的竖式计算的思路,两个数相除,a要先乘以10,然后除以除数,得到一个con,然后对a*10后的结果进行求余得到余数,然后进行比较就ok啦,(#^.^#)

下面是代码:


 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>
using namespace std;


int main()
{
    int a,b,c;
    int i;
    int con;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        for(i=1;i<=100000;i++)
        {


            a=a*10;
            con=a/b;
            a=a%b;
            if(con==c)
            {
                printf("%d\n",i);
                break;
            }
        }
        if(i==100001)
        {
            printf("-1\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38984851/article/details/81048227