Perimeter of squares in a rectangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| typedef unsigned long long ull; class SumFct { public: static ull perimeter(int n) { if(n == 0) return 1ull; ull res = 0ull, fibo1 = 1, fibo2 = 1; for(ull i = 1; i < n; i++) { res += fibo1 * 4; ull fibo3 = fibo1 + fibo2; fibo1 = fibo2; fibo2 = fibo3; } return res + 4 * fibo1 + 4 * fibo2; } };
|