알고리즘

[알고리즘] 백준 2526 - 싸이클 (C++)

blueberrysoda 2024. 10. 21. 23:49

[문제 링크] : https://www.acmicpc.net/problem/2526

#include <iostream>
using namespace std;

int N, P, tmp, cnt=1;
int Arr[1001]; 

int main(){
    cin >> N >> P;
    tmp = N;
    
    while(!Arr[tmp]){
        Arr[tmp] = cnt++;
        tmp = tmp * N % P;
    }
    cout << cnt - Arr[tmp] << "\n";
    return 0;
}