Tuesday, June 16, 2015

UVa 10127 - Ones

// UVa 10127 - Ones
#include <iostream>

using namespace std;

int main() {

	int a;
	while (cin >> a) {

		int n = 1;
		int s = 1;
		while (n < a) {
			n = n * 10 + 1;
			s++;
		}

		int m = n % a;
		while (m != 0) {
			m = (m * 10 + 1) % a;
			s++;
		}

		cout << s << endl;
	}

	return 0;
}

No comments:

Post a Comment