Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

피너클의 it공부방

백준 14440 정수 수열 (c++) : 피너클 본문

백준

백준 14440 정수 수열 (c++) : 피너클

피너클 2022. 7. 19. 23:33
728x90
반응형

https://www.acmicpc.net/problem/14440

 

14440번: 정수 수열

첫째 줄에 x, y, a0, a1, n이 주어진다. (1 ≤ x, y ≤ 99, 0 ≤ n < 108) a0과 a1은 A0, A1의 마지막 두 자리이다.

www.acmicpc.net

간단한 구현문제다.

숫자를 출력할때 마지막 두자리를 출력해야된다.

1이면 01을 출력해야되고 3이면 03을 출력해야된다.

#include <iostream>

using namespace std;

int x, y, a0, a1, n;

void fib(int n) {
	int n1 = a1, n2 = a0;
	for (int i = 3; i <= n + 1; i++) {
		int n3 = x * n1 + y * n2;
		n3 %= 100;
		n2 = n1;
		n1 = n3;
	}
	if (n1 >= 10) cout << n1 << endl;
	else cout << '0' << n1 << endl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> x >> y >> a0 >> a1 >> n;
	fib(n);
}

전체코드다.

728x90
반응형
Comments