Problem:
Problem B:
Headstrong Student
You are a teacher at a cram school for elementary school pupils.
One day, you showed your students how to calculate division of fraction in a class of mathematics.
Your lesson was kind and fluent, and it seemed everything was going so well - except for one
thing. After some experiences, a student Max got so curious about how precise he could compute
the quotient. He tried many divisions asking you for a help, and finally found a case where
the answer became an infinite fraction. He was fascinated with such a case, so he continued
computing the answer. But it was clear for you the answer was an infinite fraction - no matter
how many digits he computed, he wouldn’t reach the end.
Since you have many other things to tell in today’s class, you can’t leave this as it is. So you
decided to use a computer to calculate the answer in turn of him. Actually you succeeded to
persuade him that he was going into a loop, so it was enough for him to know how long he could
compute before entering a loop.
Your task now is to write a program which computes where the recurring part starts and the
length of the recurring part, for given dividend/divisor pairs. All computation should be done
in decimal numbers. If the specified dividend/divisor pair gives a finite fraction, your program
should treat the length of the recurring part as 0.
Input
The input consists of multiple datasets. Each line of the input describes a dataset. A dataset
consists of two positive integers
x
and
y
, which specifies the dividend and the divisor, respectively.
You may assume that 1 ≤
x
<
y
≤ 1,000,000.
The last dataset is followed by a line containing two zeros. This line is not a part of datasets
and should not be processed.
Output
For each dataset, your program should output a line containing two integers separated by exactly
one blank character.
The former describes the number of digits after the decimal point before the recurring part
starts. And the latter describes the length of the recurring part.
Sample Input
1 3
1 6
3 5
2 200
25 99
0 0
Output for the Sample Input
0 1
1 1
1 0
2 0
0 2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
int m[1000005];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    while (true) {
        int x, y; cin >> x >> y;
        if (!x) break;
        for (int i = 0;i < y;i++) m[i] = 0;
        int r = x % y;
        int cnt = 0;
        while (true) {
            if (m[r] || !r) break;
            m[r] = ++cnt;
            r = (r * 10) % y;
        }
        if (!r) {
            cout << cnt << " 0\n";
        } else {
            cout << m[r] - 1 << " " << cnt - m[r] + 1 << "\n";
        }
    }
}
accuracy: 1
time_ms: 240
memory_kb: 7284
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
int m[1000005];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    while (true) {
        int x, y; cin >> x >> y;
        if (!x) break;
        for (int i = 0;i < y;i++) m[i] = 0;
        int r = x;
        int cnt = 0;
        while (true) {
            if (m[r] || !r) break;
            m[r] = ++cnt;
            r = (r * 10) % y;
        }
        if (!r) {
            cout << cnt << " 0\n";
        } else {
            cout << m[r] - 1 << " " << cnt - m[r] + 1 << "\n";
        }
    }
}
accuracy: 1
time_ms: 240
memory_kb: 7200
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int a,b; cin >> a >> b;
		if(a==0&&b==0)break;
		int g=__gcd(a,b);
		a/=g; b/=g;
		vector<int> seen(b,-1);
		seen[a]=0;
		for(int c=1;;c++){
			a=(10*a)%b;
			if(a==0){
				cout << c << " " << 0 << endl;
				break;
			}
			else if(seen[a]!=-1){
				cout << seen[a] << " " << c-seen[a] << endl;
				break;
			}
			else{
				seen[a]=c;
			}
		}
	}
	return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 6976
final_rank: 8

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;

int adiv(int a) {
	map<int,int>mp;
	int num(a);
	for (int i = 2; i <= a; ++i) {
		while (num%i == 0) {
			mp[i]++;
			num/=i;
		}
	}
	int anum=0;
	for (auto m : mp) {
		anum-=m.first;
	}
	anum+=2*prev(mp.end())->first;
	return anum;
}

int main() {
	while (true) {

		int x,y;cin>>x>>y;
		if(!x)break;
		map<int,int>mp;
		vector<int>v(1e6+1,-1);
		int ans1=0,ans2=0;
		while (true) {
			x*=10;
			int a=x/y;
			int b=x%y;

			if (b == 0) {
				ans1++;
				break;
			}
			else {
				if (v[x/10]==-1) {
					v[x/10]=ans1;
					ans1++;
					x = b;
				}
				else {
					ans2=ans1-v[x/10];
					ans1=v[x/10];
					break;
				}
			}
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 6992
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    int s[1000000]={},c=0,g=__gcd(a,b);
    a/=g,b/=g;
    while(!s[a]){
      s[a]=(++c);
      a=(a*10)%b;
      if(a<0)return 0;
    }
    if(a)c++;
    cout<<s[a]-1<<' '<<c-s[a]<<endl;
  }
}
accuracy: 1
time_ms: 250
memory_kb: 6948
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    int s[1000000]={};
    int c=0,g=__gcd(a,b);
    a/=g,b/=g;
    while(!s[a]){
      s[a]=(++c);
      a=(a*10)%b;
      if(a<0)return 0;
    }
    if(a)c++;
    cout<<s[a]-1<<' '<<c-s[a]<<endl;
  }
}
accuracy: 1
time_ms: 250
memory_kb: 6940
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int x, y;
  while(cin >> x >> y, x || y) {
    int used[1000010];
    memset(used, -1, sizeof(used));
    int i;
    used[x] = 0;
    x *= 10;
    for(i = 1; used[x%y] == -1; i++) {
      x %= y;
      used[x] = i;
      if(x == 0) break;      
      x *= 10;
    }
    cout << used[x%y] << " " << i-used[x%y] << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 10948
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  while(cin>>x>>y,x){
    int s[1000000]={};
    int c=0,gc=__gcd(x,y);
    x/=gc,y/=gc;
    while(!s[x]){
      s[x]=++c;
      x=(x*10)%y;
    }
    if(x==0)c=s[x]-1;
    cout<<s[x]-1<<" "<<c-s[x]+1<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 6944
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int M[10000000];

int main(){
  while(1){
  int n,d;
  cin>>n>>d;
  if(n==0&&d==0)break;
  
  memset(M,-1,sizeof(M));
  int cnt=0;
  while(n){
    int s = (n/d) * d;
    n -= s;
    if(M[n]!=-1)break;
    M[n] = cnt++;
    n*=10;
  }


  if(n == 0)cnt = M[n];
  cout<<M[n]<<" "<<cnt-M[n]<<endl;  
  }
  return 0;
}
accuracy: 1
time_ms: 1740
memory_kb: 42112
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
int m[1111111];
signed main(){
  int x,y;
  while(cin>>x>>y,x||y){
    int c=0;
    memset(m,-1,sizeof(m));
    while(m[x]<0){
      m[x]=c++;
      x=(x*10)%y;
      if(!x) break;
    }
    if(!x) cout<<c<<" "<<0<<endl;
    else cout<<m[x]<<" "<<c-m[x]<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 570
memory_kb: 11716
final_rank: 13

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

int* table;

void func(int X,int Y){

	int current = X%Y,ans_left,ans_right;

	table[current] = 0;

	for(int i = 1;i < 1000000; i++){
		current = (10*current)%Y;

		if(current == 0){ //?????????????????´???
			ans_left = i;
			ans_right = 0;
			break;
		}else{
			if(table[current] != -1){
				ans_left = table[current];
				ans_right = i - table[current];
				break;
			}else{
				table[current] = i;
			}
		}
	}
	printf("%d %d\n",ans_left,ans_right);
}


int main(){

	int X,Y;

	table = new int[1000010];

	while(true){
		scanf("%d %d",&X,&Y);
		if(X == 0 && Y == 0)break;

		for(int i = 0; i < Y; i++)table[i] = -1;

		func(X,Y);
	}

    return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 6660
final_rank: 2

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

int* table;

void func(int X,int Y){

	int current = X%Y,ans_left,ans_right;

	table[current] = 0;

	for(int i = 1;i < 1000000; i++){
		current = (10*current)%Y;

		if(current == 0){ //?????????????????´???
			ans_left = i;
			ans_right = 0;
			break;
		}else{
			if(table[current] != -1){
				ans_left = table[current];
				ans_right = i - table[current];
				break;
			}else{
				table[current] = i;
			}
		}
	}
	printf("%d %d\n",ans_left,ans_right);
}


int main(){

	int X,Y;

	table = new int[1000010];

	while(true){
		scanf("%d %d",&X,&Y);
		if(X == 0 && Y == 0)break;

		for(int i = 0; i < 1000010; i++)table[i] = -1;

		func(X,Y);
	}

    return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 6636
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int x,y;
  while(cin >> x >> y && x) {
    x%=y;
    unordered_map<int,int> m;
    int i;
    for(i=0; i<1000000; i++) {
      if(!x) break;
      if(m.count(x)) {
        cout << m[x] << " " << i-m[x] << endl;
        goto next;
      }
      m[x]=i;
      x*=10;
      x%=y;
    }
    cout << i << " " << 0 << endl;
    next:;
  }
  return 0;
}
accuracy: 1
time_ms: 4410
memory_kb: 42412
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
  while(1){
    unordered_map<int,int> mp;
    int x,y,c=0;
    scanf("%d %d",&x,&y);
    if(x==0&&y==0)break;
    
    while(x!=0&&mp.count(x)==0){
      mp[x]=c++;
      x*=10;
      x%=y;
    }
    if(x==0){
      cout<<c<<' '<<0<<endl;
    }else{
      cout<<mp[x]<<' '<<c-mp[x]<<endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 4540
memory_kb: 42476
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;


int x,y;
int main(){
  while( cin >> x >> y && (x||y) ){
    unordered_map<int,int> mp;
    int cnt = 0;
    while( x ){      
      if( mp.count(x) ) {
        cout << mp[x] << " " << cnt - mp[x] << endl;
        break;
      }
      mp[x] = cnt++;
      x *= 10;
      x %= y;      
    }
    if( x == 0 ) cout << cnt << " 0" << endl;
  }
}
accuracy: 1
time_ms: 4470
memory_kb: 42380
final_rank: 18

code_snippet: //============================================================================
// Name        : B.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;

int x,y;

int dp[1000010];
pair<int,int> solve(int x, int y){
	memset(dp, -1, sizeof dp);
	int c = x;
	for(int i = 0;; ++i){
		//int q = c/y;
		int r = c%y;
		if(r == 0){
			return make_pair(i, 0);
		}
		if(dp[r] != -1){
			return make_pair(dp[r], i-dp[r]);
		}
		dp[r] = i;
		c = r*10;
	}
}

int main() {
	while(cin >> x >> y && x){
		auto ans = solve(x,y);
		cout << ans.first << ' ' << ans.second << '\n';
	}
}
accuracy: 1
time_ms: 250
memory_kb: 6956
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int x, y; cin >> x >> y && (x && y);) {
    int mp[1000001]; memset(mp, -1, sizeof mp);
    int cnt = 0;
    while(!~mp[x % y]) {
      if(x % y == 0) {
        cout << cnt << " 0" << endl;
        goto exit;
      }
      mp[x % y] = cnt ++;
      x %= y;
      x *= 10;
    }
    cout << mp[x % y] << " " << cnt - mp[x % y] << endl;
    exit:;
  }
  
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 6892
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int x, y; cin >> x >> y && (x && y);) {
    unordered_map<int, int> mp;
    int cnt = 0;
    while(mp.find(x % y) == mp.end()) {
      if(x % y == 0) {
        cout << cnt << " 0" << endl;
        goto exit;
      }
      mp[x % y] = cnt ++;
      x %= y;
      x *= 10;
    }
    cout << mp[x % y] << " " << cnt - mp[x % y] << endl;
    exit:;
  }
  
  return 0;
}
accuracy: 1
time_ms: 4660
memory_kb: 42276
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

int check[10][1000001];

int main()
{
  int x, y;
  while(cin >> x >> y, x || y) {
    memset(check, -1, sizeof(check));
    int cnt = 0;
    x *= 10;
    bool flag = false;
    while(!~check[x/y][x%y]) {
      check[x/y][x%y] = cnt;
      if(x%y == 0) { flag = true; break; }
      cnt++;
      x %= y; x *= 10;
    }
    cout << check[x/y][x%y]+(int)flag << " " << cnt-check[x/y][x%y] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1920
memory_kb: 42136
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define N 10000005
using namespace std;
int m[N];
int a,b,cnt,ans1,ans2;

int main(){
  while(1){
    cin>>a>>b;
    if(!a&&!b)break;
    memset(m,-1,sizeof(m));
    a%=b;
    cnt=0;
    while(1){
      a*=10;
      if(m[a]!=-1){
	ans1=m[a],ans2=cnt-m[a];
	break;
      }
      m[a]=cnt;
      a%=b;
      if(!a){
	ans1=cnt+1,ans2=0;
	break;
      }      
      cnt++;
    }
    cout<<ans1<<' '<<ans2<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1890
memory_kb: 42032
final_rank: 15