Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Building squares using smallest amount of matches
#include <iostream> #include <cmath> /* Problem: * what is the smallest number of matches needed to make n squares * with side=1 match? n is given by user through stdin. */ //Rewrote this code in c89, but it doesn't work on Rextester int main(){ unsigned input; std::cin>>input; unsigned root=sqrt(input), squared_root=root*root; register unsigned sum=2*(squared_root+root); input-=squared_root; if(input>0) sum+=1+2*input+input/root; std::cout<<sum<<'\n'; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Zahra_matrix
czekolada
Microsoft - MaxEmployeeAttendence (R repititions - Optimised DP)
Test 01 c++
search_n algorithm
Rezolvare Ex 4
FindKthElementDivideConquer
merge-sort
Synchro#3
riemann
Please log in to post a comment.