Here is the problem link: Three Different Numbers Practice Coding Problem - CodeChef
Here is my code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long a[3];
for(int i=0;i<3;i++) cin>>a[i];
sort(a,a+3);
long k=a[0]*(a[1]-1)*(a[2]-2);
long j = pow(10,9)+7;
cout<<(k%j)<<"\n";
}
return 0;
}
My code runs on sample test cases,but i am not able to figure out the failed testcases,so help me in figuring out that.Also the problem statement is very tricky,so plz explain the problem if i interpreted it wrong.
Kindly post your algorithm,code for the problem.
@aditya8676
Its maths problem dude.
plzz refer my c++ code for better understanding.
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
long long int a[3];
for(int i=0;i<3;i++)
{
cin>>a[i];
}
sort(a,a+3);
long long int ans=1;
for(long long int i=0;i<3;i++)
{
a[i]=(a[i]-i)%1000000007;
ans=(ans*(a[i]))%1000000007;
}
cout<<ans<<endl;
}
return 0;
}
1 Like
Bro, in question it is stated:
By the way, because of this the answer could be quite large. Hence you should output it modulo 10^9 + 7 . That is you need to find the remainder of the division of the number of required triples by 10^9 + 7
so we have to modulo our answer with 10^9+7 but you have modulo it several times.Plz elaborate it.
@aditya8676
its rule bro ,
u have to do it like this only to avoid integer overflow .
just to through some documentation of modular mathematics, u will get it.