Run Code
|
API
|
Code Wall
|
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
pow implementation
FInd rows with maximum no of 1's
no copy elision
Vector impl
Operation on Set Container
getline vs cin
snake logic complete c++
PATRA_Class_test
horse aand goat working
alternate list