728x90
data type에 따른 값의 크기와,
cycle을 어떻게 처리할지에 대해 고민 할 수 있는 문제
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#include <set>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
unsigned int N,S,P,Q;
cin >> N;
cin >> S >> P >> Q;
unsigned int bigNumber = pow(2,31);
unsigned int a0 = S;
unsigned long long a = a0;
unsigned long long a1 = a0;
unsigned int i = 1;
for(; i < N; i++)
{
a = (a0*P + Q) % bigNumber;
if(a == S || a == a0 )
{
break;
}
a0 = a;
}
cout << i << endl;
return 0;
}
728x90
'개발 공부 > 알고리즘' 카테고리의 다른 글
HackerRank, C++, C++ Variadics (0) | 2022.11.08 |
---|---|
HackerRank, C++, Class Template Specialization (0) | 2022.11.05 |
HackerRank, c++, Attending Workshops (1) | 2022.11.05 |
HackerRank, c++, Operator Overloading (0) | 2022.11.05 |
HackerRank, c++, Magic Spells (1) | 2022.11.04 |