You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
InputThe first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).
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.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
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.
题意:求c出现在a/b的小数点后的多少位,不存在输出-1;
#include<bits\stdc++.h> using namespace std; const int len=1e2+3; #define ll long long int main() { int a,b,c; int w=0; cin>>a>>b>>c; a=a%b;//去掉整数位,保证b>a; int t=1e7;//保证不超时,越大越好 int sum=0;//计数 while(t--) { sum++; a=a*10; int ans=a/b%10;//a的第一位小数为a*10/b //ans为a/b的sum位小数 if(ans==c) { w=1; break; } a=a%b;//去掉整数部分 } if(w)cout<<sum<<endl; else puts("-1"); }