백준 11444 c++

magicdrill·2024년 4월 3일

백준 문제풀이

목록 보기
254/673

백준 11444 c++

#include <iostream>

using namespace std;
long long int n;
long long int A[2][2] = { 1, 1, 1, 0 };
long long int result[2][2] = { 1, 0, 0, 1 };


long long int input(long long int lower, long long int upper)
{
	//cout << "input()" << endl;
	long long int A;

	while (1)
	{
		cin >> A;
		if (A >= lower && A <= upper)
		{
			break;
		}
		else
		{
			;
		}
	}

	return A;
}

void print_matrix(long long int arr[2][2], int col, int row)
{
	int i, j;

	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 2; j++)
		{
			cout << arr[i][j] << " ";
		}
		cout << "\n";
	}

	return;
}

void pow_matrix(long long int front[2][2], long long int back[2][2])
{
	int i, j, k;
	long long int temp[2][2];

	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 2; j++)
		{
			temp[i][j] = 0;
			for (k = 0; k < 2; k++)
			{
				temp[i][j] += (front[i][k] * back[k][j]);
			}
			temp[i][j] = temp[i][j] % 1000000007;
		}
	}
	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 2; j++)
		{
			front[i][j] = temp[i][j];
		}
	}

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	n = input(1, 1000000000000000000);
	while (n > 0)
	{
		if (n % 2 == 1)
		{
			pow_matrix(result, A);
		}
		else
		{
			;
		}
		pow_matrix(A, A);
		n = n / 2;
	}

	cout << result[1][0] << "\n";

	return 0;
}

0개의 댓글