summaryrefslogtreecommitdiff
path: root/PlaygroundCpp/Sources
diff options
context:
space:
mode:
Diffstat (limited to 'PlaygroundCpp/Sources')
-rw-r--r--PlaygroundCpp/Sources/Playground.cpp57
1 files changed, 25 insertions, 32 deletions
diff --git a/PlaygroundCpp/Sources/Playground.cpp b/PlaygroundCpp/Sources/Playground.cpp
index 4445c37..c737a3c 100644
--- a/PlaygroundCpp/Sources/Playground.cpp
+++ b/PlaygroundCpp/Sources/Playground.cpp
@@ -26,46 +26,39 @@ static int getLastDigit(long n) {
else
return result - 1;
}
+static int getLastDigit(long m, long n) {
+ if (m == n)
+ return getFibNModM(n);
+ else {
+ int sumFn = getLastDigit(n);
+ int sumFm;
+ if (m <= 1)
+ sumFm = 0;
+ else
+ sumFm = getLastDigit(m - 1);
+ if (sumFn >= sumFm)
+ return sumFn - sumFm;
+ else
+ return sumFn - sumFm + 10;
+ }
+}
-//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(FibPartialSumLastDigit, Five_Five) {
+// ASSERT_EQ(getLastDigit(5, 5), 5);
//}
//
-//TEST(FibLastDigitTest, ThreeThreeOne) {
-// ASSERT_EQ(4, getGCD(14159572, 63967072));
+//TEST(FibPartialSumLastDigit, Ten_200) {
+// ASSERT_EQ(getLastDigit(10, 200), 2);
//}
//
-//TEST(FibLastDigitTest, ReverseAB) {
-// ASSERT_EQ(4, getGCD(14159572, 63967072));
+//TEST(FibPartialSumLastDigit, One_2) {
+// ASSERT_EQ(getLastDigit(1, 2), 2);
//}
int main() {
- long n;
+ long m, n;
+ std::cin >> m;
std::cin >> n;
- int c = getLastDigit(n);
+ int c = getLastDigit(m, n);
std::cout << c << '\n';
}