Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

souvikmahato's blog

By souvikmahato, history, 4 weeks ago, In English,

Here , is a very simple algorithm to the above problem in O(1).

if x=1, then no solution exists , thus print -1. else for any x , print a=x , b=x . u can see it satisfies all the condition :- 1) a%b=0: x%x=0, 2)a.b > x : x.x >x , 3)a/b < x : x/x <x .

Hope u get this solution and can easily solve the problem.

here is my solution:-

#include<bits/stdc++.h>
    using namespace std;

    int main()
    {
        int x;
        cin>>x;
        if(x==1)
          {
              cout<<-1;
              return 0;
          }
        else
          {
              cout<<x<<" "<<x;
          }
    }
 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by souvikmahato (previous revision, new revision, compare).

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by souvikmahato (previous revision, new revision, compare).

»
4 weeks ago, # |
  Vote: I like it +13 Vote: I do not like it

Wow! Thanks! I can't solve this problem for an year! You are the best!

»
4 weeks ago, # |
Rev. 2   Vote: I like it +13 Vote: I do not like it

Wow, how you arrived with this? Please also add your though process.

»
4 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In the third condition it is a/b < x not a/b > x. I think it was a typo.