Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
The single line contains a single integer n (0 ≤ n ≤ 10105). The number doesn't contain any leading zeroes.
Print the value of the expression without leading zeros.
4
4
124356983594583453458888889
0
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
解题说明:此题通过找规律来做,首先分别考虑每个数与5的模,
1^n mod 5 = 1 ;
2^n mod 5 = 随着n从0开始,结果为 1 2 4 3 1 2 4 3 1 2 4 3 。。。。以1 2 4 3 循环3^n mod 5 = 随着n从0开始,结果为 1 3 4 2 1 3 4 2 1 3 4 2.。。。。以1 3 4 2 循环
4^n mod 5 = 。。。。结果为 1 4 1 4 1 4 以1 4 循环
每一位累加之后,发现以4 0 0 0 4循环,于是求和对5的模只需要判断是否是4的倍数即可
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
long long n;
scanf("%d",&n);
if(n%4==0)
{
printf("4\n");
}
else
{
printf("0\n");
}
return 0;
}