[Codewars] Magnet particules in boxes

Magnet particules in boxes

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
class Magnets
{
public:
static double doubles(int maxk, int maxn);
};

double Magnets::doubles(int maxk, int maxn) {
double res = 0.;
auto v = [](double i, double j) {
return 1. / i / pow(j+1,2*i);
};
for(int i = 1; i <= maxk; i++) {
for(int j = 1; j <= maxn; j++) {
res += v(i,j);
}
}
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/05/PS/Codewars/magnet-particules-in-boxes/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.