Source Code: #include using namespace std; #define fastread() { ios::sync_with_stdio(0);cin.tie(0);} #define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){ #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif fastread(); /* To solve this problem, I first thought of getting rid of as many 2020's as possible from an example input, and we get some number that is just smaller than 2020 that we can no longer substract. One interesting thing I noted was that 2021 is simply just 1 away from 2020, so how ever many 2020's I removed, the remaining number could potentially be the number of 2021's that I would need. For example, if our number was 8081, then I would substract 2020 about 4 times, which would get us currently 1, and this 1 is actually the number of 2021 used. So the general formula we can use is: Subtract as many 2020's as you can, and the remaining number multiply by 2021, and try substracting from the original input value, and see if now the difference we just got is divisible by 2020. If it is, we're good, and if not, we're not good. One point is that if the number is too big it is also invalid. For example, If I tried 2030-2020, I get 10 as the remainder, but clearly 2030 - 2021*10 is simply too big, and would be negative. Once we just check for this edge case, we should be good to go :D */ int n,input; cin >> n; while(n--) { cin >> input; if(input % 2020 == 0 || input % 2021 == 0) cout = 0 and partial2021 % 2020 == 0) cout
Source Code:
#include
using namespace std;
#define fastread() { ios::sync_with_stdio(0);cin.tie(0);}
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
fastread();
/*
To solve this problem, I first thought of getting rid of as many
2020's as possible from an example input, and we get some number
that is just smaller than 2020 that we can no longer substract.
One interesting thing I noted was that 2021 is simply just 1 away from
2020, so how ever many 2020's I removed, the remaining number could
potentially be the number of 2021's that I would need. For example,
if our number was 8081, then I would substract 2020 about 4 times,
which would get us currently 1, and this 1 is actually the number
of 2021 used. So the general formula we can use is: Subtract as many
2020's as you can, and the remaining number multiply by 2021, and
try substracting from the original input value, and see if now the
difference we just got is divisible by 2020. If it is, we're good,
and if not, we're not good. One point is that if the number is too big
it is also invalid. For example, If I tried 2030-2020, I get 10 as the
remainder, but clearly 2030 - 2021*10 is simply too big, and would be
negative. Once we just check for this edge case, we should be good to go :D
*/
int n,input;
cin >> n;
while(n--) {
cin >> input;
if(input % 2020 == 0 || input % 2021 == 0) cout = 0 and partial2021 % 2020 == 0) cout