The difference between the last two digits is 3

View Discussion

Improve Article

Save Article

Like Article

Given a positive N, the task is to find the last two digits of 7N.
Examples: 
 

Input: N = 5 
Output: 07 
Explanation: 
The value of 75 = 7 * 7 * 7 * 7 * 7 = 8507 Therefore, the last two digits are 07.

Input: N = 12 


Output: 01 
Explanation: 
The value of 712 = 13841287201 Therefore, the last two digits are 01. 

Approach: A general approach to finding the last K digits of XY is to discuss this article in logarithmic time complexity. In this article, we will discuss the constant time solution.
Below is the observation for the value of 7N for some values of N
 

71 = 7 last two digit = 07 
72 = 49 last two digit = 49 
73 = 243 last two digit = 43 
74 = 2401 last two digit = 01
75 = 16807 last two digit = 07 
76 = 117649 last two digit = 49 
77 = 823543 last two digit = 43 
78 = 5764801 last two digit = 01 
 

Based on the above observations we have the following cases: 
 

  1. If the last two digit in 7N = 07 when N = 4K + 3.
  2. If the last two digit in 7N = 49 when N = 4K + 2.
  3. If the last two digit in 7N = 43 when N = 4K + 1.
  4. If the last two digit in 7N = 01 when N = 4K.

Below is the implementation of the above approach:
 

#include <bits/stdc++.h>

using namespace std;

string get_last_two_digit(int N)

{

    if (N % 4 == 0)

        return "01";

    else if (N % 4 == 1)

        return "07";

    else if (N % 4 == 2)

        return "49";

    return "43";

}

int main()

{

    int N = 12;

    cout << get_last_two_digit(N);

    return 0;

}

import java.io.*;

import java.util.*;

class GFG{

public static String get_last_two_digit(int N)

{

    if (N % 4 == 0)

        return "01";

    else if (N % 4 == 1)

        return "07";

    else if (N % 4 == 2)

        return "49";

    return "43";

}

public static void main(String[] args)

{

    int N = 12;

    System.out.println(get_last_two_digit(N));

}

}

def get_last_two_digit(N):

    if (N % 4 == 0):

        return "01";

    elif (N % 4 == 1):

        return "07";

    elif (N % 4 == 2):

        return "49";

    return "43";

N = 12;

print( get_last_two_digit(N))

using System;

namespace GFG{

class GFG{

public static String get_last_two_digit(int N)

{

    if (N % 4 == 0)

        return "01";

    else if (N % 4 == 1)

        return "07";

    else if (N % 4 == 2)

        return "49";

    return "43";

}

public static void Main()

{

    int N = 12;

    Console.Write(get_last_two_digit(N));

}

}

}

<script>

    function get_last_two_digit(N)

    {

        if (N % 4 == 0)

            return "01";

        else if (N % 4 == 1)

            return "07";

        else if (N % 4 == 2)

            return "49";

        return "43";

    }

        var N = 12;

        document.write(get_last_two_digit(N));

</script>

Time Complexity: O(1) 
Auxiliary Space: O(1)
 



Correct Answer:

Description for Correct answer:

Three digit number \( \Large =100x+10y+z \)To make number after changing last two digit\( \Large =100x+10z+y \)Now,\( \Large 100x+10y+z=100x+10z+y-45 \)\( \Large 9z-9y=45 \)

\( \Large z-y=5 \)


Part of solved Number series questions and answers : >> Aptitude >> Number series

Comments

Similar Questions

No worries! We‘ve got your back. Try BYJU‘S free classes today!

No worries! We‘ve got your back. Try BYJU‘S free classes today!

No worries! We‘ve got your back. Try BYJU‘S free classes today!

No worries! We‘ve got your back. Try BYJU‘S free classes today!

Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses