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
2
proga2
break.cpp
decode
substr
Test 5(2020)
Minimum Vertices to Traverse Directed Graph
D three integers
不带头结点的单链表
MACRO