codeforces 260 div2 B题

打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被4整出即可。

#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string str;
    cin >> str;
    int len = str.size(), num;
    if(len == 1){
        num = str[0]-'0';
    }
    else {
        num = (str[len-2]-'0')*10 + str[len-1]-'0';
    }
    if(num % 4==0) printf("4
");
    else printf("0
");
}

原文地址:https://www.cnblogs.com/anhuizhiye/p/3933119.html