B - Fedya and Maths
B - Fedya and Maths
思路
找到规律发现答案以4为周期循环
如果被4整除那么答案则为4,否则答案为0
疑难
一个长度为\(10^5\)的数怎么对4进行取模运算?
分别取模
如:
\[12345678987654321 \ \ mod \ \ 4
\]
\[= (12345678987654300 + 21) \ \ mod \ \ 4
\]
\[= 21 \ \ mod \ \ 4
\]
显然,取模的值只与后两位有关!!!
代码
点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define X first
#define Y second
typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 1e6+10;
const int M = 2e5+10;
int n,m;
void solve(){
string s;
cin >> s;
if(s.size() == 1){
int t = s[0] - '0';
if(t % 4 == 0)cout << 4;
else cout << 0;
}
else if(s.size() >= 2){
int t = (s[s.size() - 2] - '0') * 10 + (s[s.size() - 1] - '0');
if(t % 4 == 0)cout << 4;
else cout << 0;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
solve();
}