summaryrefslogtreecommitdiff
path: root/PlaygroundCpp/Sources/Playground.cpp
blob: 4445c37e6f894c54019fd1e2942223350d8cace8 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
//#include <gtest/gtest.h>

const int FIB_PISANO_PERIOD_FOR_TEN = 60;

static int getFibNModM(long n) {
	long r = n % FIB_PISANO_PERIOD_FOR_TEN;
	if (r == 0)
		return 0;
	int firstN = 0;
	int secondN = 1;
	int tempHolder = 1;
	for (int i = 1; i < r; i++) {
		tempHolder = (firstN + secondN) % 10;
		firstN = secondN;
		secondN = tempHolder;
	}
	return secondN;
}
static int getLastDigit(long n) {
	if (n <= 1)
		return (int) n;
	int result = getFibNModM(n + 2);
	if (result == 0)
		return 9;
	else
		return result - 1;
}

//TEST(FibSumLastDigitTest, Zero) {
//	ASSERT_EQ(getLastDigit(0), 0);
//}
//TEST(FibSumLastDigitTest, One) {
//	ASSERT_EQ(getLastDigit(1), 1);
//}
//TEST(FibSumLastDigitTest, Six) {
//	ASSERT_EQ(getLastDigit(6), 0);
//}
//TEST(FibSumLastDigitTest, Nine) {
//	ASSERT_EQ(getLastDigit(9), 8);
//}
//TEST(FibSumLastDigitTest, OneHundred) {
//	ASSERT_EQ(getLastDigit(100), 5);
//}

//TEST(FibLastDigitTest, One) {
//	ASSERT_EQ(getFibNModM(239, 1000), 161);
//}
//
//TEST(FibLastDigitTest, Three) {
//	ASSERT_EQ(getFibNModM(2816213588, 30524), 10249);
//}

//TEST(FibLastDigitTest, Forty) {
//	ASSERT_EQ(1344, getGCD(1344, 1344));
//}
//
//TEST(FibLastDigitTest, ThreeThreeOne) {
//	ASSERT_EQ(4, getGCD(14159572, 63967072));
//}
//
//TEST(FibLastDigitTest, ReverseAB) {
//	ASSERT_EQ(4, getGCD(14159572, 63967072));
//}

int main() {
	long n;
	std::cin >> n;
	int c = getLastDigit(n);
	std::cout << c << '\n';
}