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
output
input
output
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
无奈之下,打表看一看(很常见的手段),发现N是4的倍数时,答案为4,其余时候,答案为0。
判断是否为4的倍数,只需要将最后两位数取下来,看是否为4的倍数。
#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");
}
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 Round #237(div2) B解题报告
- 解题报告:Codeforces Round #424 Div. 2 C. Jury Marks 记录STL::map的一个小细节
- codeforces Round #237(div2) D解题报告
- Codeforces Round #306 (Div. 2) D.E. 解题报告
- 【解题报告】Codeforces Round #303 (Div. 2)
- Codeforces 474(#271 Div 2) 解题报告
- Codeforces Round #271 (Div. 2) 解题报告
- Codeforces Round #382 (Div. 2) 解题报告
- codeforces Round #263(div2) E解题报告
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps 解题报告
- codeforces Round #260(div2) C解题报告
- codeforces Round #259(div2) E解题报告
- codeforces Round #258(div2) D解题报告
- Codeforces Round #180 (Div. 2) 解题报告
- Codeforces Round #216 (Div. 2) 解题报告
- Codeforces Round #280 (Div. 2) 解题报告(A B C D E)
- 解题报告:Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers 暴力
- Codeforces Round #372 (Div. 1) B. Complete The Graph 解题报告
- 【解题报告】Codeforces Round #372 (Div. 2)
- Codeforces Round #179 (Div. 2) A题解题报告