Hi everyone! This is my very first blog post here on Codeforces. I am still quite new to competitive programming and trying my best to learn new algorithms every day.
Today, I was looking at a problem called H. Simple Mod and found something so funny that I just had to share it.
When I first opened the problem, the constraints looked absolutely terrifying: * We are given a huge number $$$N$$$ that can have up to 100 digits ($$$1 \le N \le 10^{100}$$$). * We need to find two integers $$$X$$$ and $$$Y$$$ such that $$$(X^2 + Y^2) \pmod N = 0$$$.
Looking at the examples, they showed outputs like 4 3 and 5 5. I immediately started worrying. How am I supposed to handle a 100-digit number in C++? Do I need to learn complex math or big-integer coding just to solve this?
I sat there staring at the screen, and then I carefully re-read this specific line in the problem description:
"...such that $$$X$$$ and $$$Y$$$ are non-negative integers."
Non-negative means the numbers cannot be negative, but they can be zero!
So, what happens if we just choose $$$X = 0$$$ and $$$Y = 0$$$? * $$$X^2 + Y^2 = 0^2 + 0^2 = 0$$$ * $$$0 \pmod N = 0$$$
It does not matter if $$$N$$$ is 5, 50, or a giant 100-digit number. Zero divided by anything always leaves a remainder of zero. Plus, $$$0$$$ is definitely less than $$$10^9$$$, which satisfies the output limit!
The Easiest Code Ever Written
Here is the exact code that gets Accepted. Notice that we read $$$N$$$ as a string so the 100-digit number doesn't overflow our code!
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
cout << "0 0"<<endl;
return 0;
}
Conclusion
As a beginner, this taught me a really valuable lesson: always read the constraints and definitions very carefully. Sometimes, the problem setter leaves a tiny loophole that turns a hard problem into a 1-second solution.
Have you guys ever found a funny shortcut like this? Let me know in the comments! Thanks for reading my first post!







