Algorithm
Problem Name: 2 AD-HOC - beecrowd | 2590
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2590
Seven
By Ricardo Martins, IFSULDEMINAS Brazil
Timelimit: 1
Chagas is a boy who loves to eat boiled eggs, but he hates math. He hates exponentiation and for some reason does not correctly calculate operations involving the number 7. Knowing this, his friend Caco decided to make a challenge: he wants Chagas to calculate the Nth power of 7 and say the last digit of that power. If Chagas hit all The questions, I would get 7 boiled eggs. For example, where N = 2, the result would be 9, because 72 = 49. The problem is that, depending on the value of N, the result of exponentiation can be a very large number. Without ideas, Chagas decided to ask for his help.
Write a program that, given a number, calculate the last digit of the value of 7 raised to that number.
Input
The entry consists of several instances. The first line of the entry contains an integer T indicating the number of instances. Each instance is composed of only one row, which contains the integer N (0 ≤ N ≤ 109).
Output
For each instance in the entry, print a line containing an integer, the last digit of 7N.
Input Sample | Output Sample |
4 |
7 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#define true 1
#define false 0
typedef unsigned long long llu;
int main (int argc, char **argv)
{
llu n, m;
char l_digit[] = { 1, 7, 9, 3 };
scanf("%llu", &m);
while (m--)
scanf("%llu", &n), printf("%hhd\n", l_digit[n % 4]);
return 0;
}
Copy The Code &
Try With Live Editor
Input
1
2
7
8
Output
9
3
1