We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Closest Number
Closest Number
+ 13 comments I think this one belongs in the easy category.
[deleted] + 16 comments Proud to say my code is shorter than the Editorials:
#include <cmath> #include <iostream> #include <algorithm> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int a,b,c; cin >> a >> b >> c; unsigned long long d = pow(a,b) + c / 2; cout << d - (d % c) << endl; } return 0; }
+ 2 comments I found it quite devious that test 0 only tests for truncation, not for rounding, which i suspect is why we see a lot of confused people in the comments. Adding even one example would so many people figure it out on their own.
+ 2 comments python 3
def closestNumber(a, b, x): f=(math.floor((a**b)/x)*x) c=(math.ceil((a**b)/x)*x) if((a**b)-f<c-(a**b)): return f return c
+ 1 comment JS one line:
console.log(x*Math.round(Math.pow(a,b)/x));
Difficulty should set to easy...
Load more conversations
Sort 1387 Discussions, By:
Please Login in order to post a comment