in order to take the ceil value. Assume we are dividing 15 by 7 this will give some value 2.1.. but i'm and interested in value that should be greater than 2 so if i add n-1 that is 6 in this case it will be 21/7 that will give me 3.
#include #include using namespace std; long long power(long long base, long long exp, long long limit) { long long result = 1; while (exp > 0) { if (result > limit / base) return limit + 1; result *= base; exp--; } return result; } void solve() { long long k, l1, r1, l2, r2; cin >> k >> l1 >> r1 >> l2 >> r2; long long count = 0; for (long long n = 0;; ++n) { long long kn = power(k, n, r2); if (kn > r2) break; long long min_x = max(l1, (l2 + kn - 1) / kn); long long max_x = min(r1, r2 / kn); if (min_x
why (l2+kn-1)/kn.Could u please explain
in order to take the ceil value. Assume we are dividing 15 by 7 this will give some value 2.1.. but i'm and interested in value that should be greater than 2 so if i add n-1 that is 6 in this case it will be 21/7 that will give me 3.
@@codeNLearnNCode ok so its basically an alt to ceil method
Yes
sir can u provide the solution link i
#include
#include
using namespace std;
long long power(long long base, long long exp, long long limit)
{
long long result = 1;
while (exp > 0)
{
if (result > limit / base)
return limit + 1;
result *= base;
exp--;
}
return result;
}
void solve()
{
long long k, l1, r1, l2, r2;
cin >> k >> l1 >> r1 >> l2 >> r2;
long long count = 0;
for (long long n = 0;; ++n)
{
long long kn = power(k, n, r2);
if (kn > r2)
break;
long long min_x = max(l1, (l2 + kn - 1) / kn);
long long max_x = min(r1, r2 / kn);
if (min_x