raihan-hosen's blog

By raihan-hosen, 36 hours ago, In English

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!

  • Vote: I like it
  • -18
  • Vote: I do not like it

»
35 hours ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

link?

alright, i checked and this wasnt an official contest prob. (exactly what i thought)

  • »
    »
    35 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yeah, I found it in a private group's problem set. Here is the link: https://codeforces.me/group/MWSDmqGsZm/contest/326907/problem/H

    • »
      »
      »
      26 hours ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Bro this is an april fools problem not a real problem

»
26 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Firstly I don't think this is a very difficult problem. Secondly this seems to be the intended solution and not a cheese given that if n is 10^90, 0 0 is the only possible solution because sum of squares of two nonnegative numbers under a billion cannot be greater than or equal to 10^90 and thus if mod 10^90 it must be 0 0

»
18 hours ago, hide # |
← Rev. 3  
Vote: I like it 0 Vote: I do not like it

no need to input

shortest code (3 char)