mod 곱셈연산 : (A * B) mod C = (A mod C * B mod C) mod
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
while(cin >> n){
int i = 1;
long long ret = 1 % n;
int mem = 1 % n;
while(ret){
mem = ( (10 % n) * mem ) % n;
ret = (mem + ret) % n;
i++;
}
cout << i << '\n';
}
return 0;
}
cnt = (cnt + 10 + 1)
을 바로 해도 상관없게 된다.cnt = (cnt % n * 10 % n) + 1
가 된다.#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
while(cin >> n){
int cnt = 1, ret = 1;
while(cnt % n){
cnt = (cnt * 10) + 1;
cnt %= n;
ret++;
}
cout << ret << '\n';
}
return 0;
}