Codeforces Round #450 (Div. 2) B

ACM_e發表於2017-12-21

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;
}


相關文章