【Codeforces Round #450 (Div. 2) B】Position in Fraction

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

找循环节就好。 ->其实可以不用找出来整个循环节。 有找到c就直接输出。 找到了循环节还没找到的话,直接输出无解。

【代码】

#include <bits/stdc++.h>
using namespace std;
 
int a,b,c;
int bo[(int)2e5];
 
int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> a >> b >> c;
    vector <int> v;v.clear();

    bo[a%b] = 1;
    int now = (a%b)*10;
    while (1){
        v.push_back(now/b);
        if (bo[now%b]==1){
            break;
        }
        if (now%b==0) break;
        bo[now%b] = 1;
        now = (now%b)*10;
    }
    if (now%b==0) v.push_back(0);
    for (int i = 0;i < (int)v.size();i++){
		if (v[i]==c){
		 	cout <<i+1<<endl;
		 	return 0;
		}
	}
	cout <<-1<<endl;
    return 0;
}
posted @ 2017-12-12 03:40  AWCXV  阅读(177)  评论(0编辑  收藏  举报