4B: Fedya and Maths

题目来源
Fedya studies in a gymnasium. Fedya’s maths hometask is to calculate the following expression:

(1^n + 2^n +  3^n  +  4^n) mod 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 ≤ 1e105). 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

题意

对于每个输入的n, 输出取模的结果, (n非常大,只能用char数组来存)

解法

不难发现当 n%4==0时, 取模结果为4, 其余情况为0(打个表找下规律或者自己手算一下就可以发现了),而对于n的整百部分, 一定可以被4整除,判断一下最后两位就可以了

代码

#include <iostream>
#include <cstring>
using namespace std;

char s[1000005];
int main(){
	cin >> s;
	int len = strlen(s);
	int k;
	if(len >=2) k = (s[len-2] -'0')*10 + s[len-1] - '0';
	else k = s[len-1]-'0';
	if(k%4==0) cout << 4 << endl;
	else cout << 0 << endl;
	
	return 0;
}
发布了14 篇原创文章 · 获赞 0 · 访问量 147

猜你喜欢

转载自blog.csdn.net/loaf_/article/details/104010517