Codeforces Round #260 (Div. 2) B. Fedya and Maths (数学规律)

B. Fedya and Maths
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:

(1n + 2n + 3n + 4nmod 5

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).

Input

The single line contains a single integer n (0 ≤ n ≤ 10105). The number doesn't contain any leading zeroes.

Output

Print the value of the expression without leading zeros.

Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note

Operation x mod y means taking remainder after division x by y.

Note to the first sample:

题意:求(1^n+2^n+3^n+4^n)mod5的值


思路:我们会发现2的循环节为4,3的循环节为4,4的循环节为2,然后直接验证各个次方的末尾数就可以啦


ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
char s[MAXN];
int a[4]={6,2,4,8},b[4]={1,3,9,27},c[2]={6,4};
int main()
{
	while(scanf("%s",s)!=EOF)
	{
		int len=strlen(s);
		int num=s[len-1];
		if(len>1)
		num+=(s[len-2]-'0')*10;
		int ans;
		ans=a[num%4]+b[num%4]+c[num%2]+1;
		printf("%d\n",ans%5);
	}
	return 0;
}


你可能感兴趣的:(Codeforces Round #260 (Div. 2) B. Fedya and Maths (数学规律))