Codeforces 456B Fedya and Maths(数学)

来源:互联网 发布:c语言getchar函数用法 编辑:程序博客网 时间:2024/05/21 17:57

题目链接:Codeforces 456B Fedya and Maths

题目大意:给定一个数n,求题目给定公式的值。

解题思路:n为4的倍数时答案为4,否则为0,取模质数时的性质,以前做过相同的题目。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5+5;char s[maxn];int main () {    scanf("%s", s);    int len = strlen(s);    int ans = 0;    for (int i = 0; i < len; i++)        ans = (ans * 10 + s[i] - '0') % 4;    printf("%d\n", ans == 0 ? 4 : 0);    return 0;}
0 0
原创粉丝点击