Codeforces 260 B. Fedya and Maths

题目链接:http://codeforces.com/contest/456/problem/B

解题报告:输入一个n,让你判断(1n + 2n + 3n + 4nmod 5的结果是多少?注意n的范围很大很大 n (0 ≤ n ≤ 10105).

只要判断是否能被整除4就可以了,如果n能被4整除,则结果是4,如果不能,则结果是0

但n很长,不能直接mod,但只要判断最低的两位能不能被4整除就可以了,如果n只有一位就判断最低的一位。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<deque>
 7 #include<queue>
 8 #include<set>
 9 #include<map>
10 using namespace std;
11 #define maxn 100005
12 char str[maxn];
13 int main()
14 {
15     while(scanf("%s",str)!=EOF)
16     {
17         int temp,len = strlen(str);
18         if(len <= 1)
19         temp = str[0] - '0';
20         else temp = 10 * (str[len - 2] - '0') + (str[len - 1] - '0');
21         printf(temp % 4? "0
":"4
");
22     }
23     return 0;
24 }
View Code
原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3903459.html