Description
You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Sample Input
1 2 0
2
2 3 7
-1
Hint
The fraction in the first example has the following decimal notation: . The first zero stands on second position.
The fraction in the second example has the following decimal notation: . There is no digit 7 in decimal notation of the fraction.
代码如下:
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include<ctime>
#define maxn 10007
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.00000001
using namespace std;
typedef long long ll;
int main()
{
int a,b,i,c;
cin>>a>>b>>c;
int s[1111]={0};
bool flag=0;
for(i=1;i<1000;i++)
{
s[i]=a*10/b;
a=a*10%b;
if(s[i]==c)
{
flag=1;
break;
}
}
if(flag==1)
cout<<i<<endl;
else
cout<<"-1"<<endl;
}