您的位置:首页 > 其它

codeforces Round #260(div2) B解题报告

2014-10-23 21:07 239 查看
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 + 4n) 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 ≤ 10105).
The number doesn't contain any leading zeroes.

Output

Print the value of the expression without leading zeros.

Sample test(s)

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:



题目大意:

给出n,要求求出 (1^n + 2^n +3^n +4^n) mod 5的答案

解法:

数字太大了,肯定不能死算,第一反应肯定数字跟答案有关,但又总结不出数学规律。

无奈之下,打表看一看(很常见的手段),发现N是4的倍数时,答案为4,其余时候,答案为0。

判断是否为4的倍数,只需要将最后两位数取下来,看是否为4的倍数。

代码:

#include <cstdio>
#include <cstring>
#define N_max 123456

using namespace std;

char st[N_max];
int ans;

int main() {
scanf("%s", st);
if (strlen(st) >= 2)
ans = (st[strlen(st)-2] - '0')*10 + st[strlen(st)-1] -'0';
else
ans = st[strlen(st)-1] - '0';

if (ans%4 == 0)
printf("4\n");
else
printf("0\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces acm math