1 #include <iostream>
 2 #include <set>
 3 #include <vector>
 4 
 5 #ifdef __EMSCRIPTEN__
 6 #include <emscripten.h>
 7 #endif
 8 
 9 using namespace std;
10 
11 int main() {
12 #ifdef __EMSCRIPTEN__
13   int n = EM_ASM_INT({
14     return parseInt(prompt(
15         "Enter the number of rows/columns in the multiplication table:"));
16   });
17 #else
18   int n;
19   cout << "Enter the number of rows/columns in the multiplication table:"
20        << endl;
21   cin >> n;
22 #endif
23   cout << "Calculating the distribution of numbers in " << n << "x" << n
24        << " multiplication table..." << endl;
25   set<int> numbersOccuringInTable;
26   for (int i = 1; i <= n; i++)
27     for (int j = 1; j <= n; j++)
28       numbersOccuringInTable.insert(i * j);
29   vector<int> frequency(n + 1);
30   for (set<int>::iterator i = numbersOccuringInTable.begin();
31        i != numbersOccuringInTable.end(); i++)
32     frequency[(*i) / n]++;
33   int intervalsOfGrowth = 0;
34   for (int i = 1; i < n + 1; i++)
35     if (frequency[i] > frequency[i - 1]) {
36       cout << "Between " << (i - 1) * n << " and " << i * n - 1 << " there are "
37            << frequency[i - 1] << " numbers." << endl;
38       cout << "Between " << i * n << " and " << (i + 1) * n - 1 << " there are "
39            << frequency[i] << " numbers." << endl;
40       intervalsOfGrowth++;
41     }
42   cout << "There are " << intervalsOfGrowth << " intervals of growth." << endl;
43 }