MinPerimeterRectangle 發表於 2023-02-13 | 分類於 codility , Prime and composite numbers problemsolution12345678910111213141516// you can use includes, for example:// #include <algorithm>// you can write to stdout for debugging purposes, e.g.// cout << "this is a debug message" << endl;int solution(int N) { // write your code in C++14 (g++ 6.2.0) int perimeter = (N+1); for(int i=1;i*i<=N ; ++i){ if(N%i ==0){ perimeter = min(perimeter, i+N/i); } } return 2*perimeter;} analysis time complexity O(sqrt(n)) space complexity O(1)