Codeforces Round #450 (Div. 2) B

来源:互联网 发布:mac版的excel怎么换行 编辑:程序博客网 时间:2024/05/29 12:19

B. Position in Fraction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 abc (1 ≤ a < b ≤ 1050 ≤ 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.

Examples
input
1 2 0
output
2
input
2 3 7
output
-1
Note

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<bits/stdc++.h>using namespace std;int main(){  int a,b,c;  cin>>a>>b>>c;  int k=0,i;  for(int j=1;j<=100000;j++){     if(a*10<b&&a!=0){        i=0;        a=a*10;     }     else{         a=a*10;         i=a/b;         a=a%b;     }     //cout<<a<<" "<<i<<endl;     if(i==c){        cout<<j<<endl;        return 0;     }  }  cout<<"-1"<<endl;  return 0;}


原创粉丝点击