Codeforces 743C. Vladik and fractions Solution
( 1 / n ) = ( 1 /x ) + ( 1/y )
We have to form this above equation , Now place (n+1) in place of x , because if we put n instead of x then value of of y will be infinity . So , we will place the maximum value as possible So now , ( 1 / n )-( 1 /x ) = ( 1/y )
=> ( 1 / n )-( 1 / (n+1) ) = ( 1/y )
=> ( 1 / (n*(n+1) ) = ( 1 / y )
=> So , y will be the value of n*(n+1) to make form like ( 1 / n ) = ( 1 /x ) + ( 1/y )
Here , one question should be asked that why we put value ( n + 1) instead of x not other value like ( n+2 ), (n+3 )....... Because if we put (n+2) instead of x then the equation will be like in the form ( 2 / (n*(n+2) ) = ( 1 / y ) ,But this is not our expected form ...same thing for any value without only (n+1) ,
So , we can write ( 1 / (n*(n+1) ) + ( 1 / n) = ( 1 / n )
( 2 / n ) = ( 1 / n ) + ( 1/ n)
=> ( 1 / n ) + ( 1 / (n*(n+1) ) + ( 1 / n)
So , now ( 2/n ) can be expressed as sum of three expected fractions . Be happy and implement now
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
long long n;
cin>>n;
if(n==1)
cout<<"-1"<<endl;
else
cout<<n<<" "<<n+1<<" "<<n*(n+1)<<endl;
}
No comments