CodeForces

A. Arpa’s hard exam and Mehrdad’s naive cheat
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.

Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.

Mehrdad has become quite confused and wants you to help him. Please help, although it’s a naive cheat.

Input
The single line of input contains one integer n (0  ≤  n  ≤  109).

Output
Print single integer — the last digit of 1378n.

Examples
input
1
output
8
input
2
output
4
Note
In the first example, last digit of 13781 = 1378 is 8.

In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.
题意:计算1378的N次方的个位数是多少,N范围小于1e9

不难看出,如果只求个位是多少,那就一直拿1378的个位8乘8再取模10即可,计算n次后得出结果,然后发现规律个位数一直在6,8,4,2,6,8·······这样循环,也就是说n取摸4后就不用再依次乘了。

#include<stdio.h>///1378的n次方的最后一位数,因此一直拿10取摸取个位乘8就好
int main()///用for循环裸乘因为是1e9也会超时,有规律的,8  6  4  2,因此取摸n就好
{
    int n,a[5]={6,8,4,2,6};
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
        {
            printf("1
");
            continue;
        }
        printf("%d
",a[n%4]);
    }
}
原文地址:https://www.cnblogs.com/kuronekonano/p/11794336.html