AtCoder Beginner Contest 246 D - 2-variable Function Solution
Problem Link: https://atcoder.jp/contests/abc246/tasks/abc246_d
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
#define mx 1e6
long long fun(long long a,long long b)
{
return a*a*a+a*a*b+a*b*b+b*b*b;
}
int main()
{
long long n,i,j,x,r,a,b;
cin>>n;
j=mx;
if(n<mx)
j=n;
x=9e18;
for(i=0; i<=mx; i++)
{
while((fun(i,j)>=n)&&(j>=0))
{
x=min(x,fun(i,j));
j--;
}
if(j<0)
break;
}
cout<<x<<endl;
}
No comments