https://www.acmicpc.net/problem/15829
#include <iostream>
#define endl "\n"
using namespace std;
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int input1;
long long answer = 0;
long long hash = 1;
char input2;
cin >> input1;
for (int i = 0; i < input1; i++) {
cin >> input2;
answer += ((input2 - '0' - 48) * hash) % 1234567891;
hash *= 31;
hash %= 1234567891;
}
cout << answer % 1234567891;
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 1546 평균 (0) | 2024.12.28 |
---|---|
C++ 알고리즘 - 백준 1259 팰린드롬수 (0) | 2024.12.28 |
C++ 알고리즘 - 백준 2798 블랙잭 (0) | 2024.12.28 |
C++ 알고리즘 - 백준 2525 오븐 시계 (0) | 2024.12.22 |
C++ 알고리즘 - 백준 1712 손익분기점 (0) | 2024.12.15 |