language: C++ 4.7.2 (gcc-4.7.2)
date: 475 days 9 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <utility>
#include <vector>
 
std::vector< std::pair<int, int> > factor_table;
void fill_sieve( int n )
{
        factor_table.resize(n+1);
        for( int i = 1; i <= n; ++i )
                factor_table[i] = std::pair<int, int>(i, 1);
        for( int j = 2, j2 = 4; j2 <= n; (j2 += j), (j2 += ++j) ) {
                if (factor_table[j].second == 1) {
                        int i = j;
                        int ij = j2;
                        while (ij <= n) {
                                factor_table[ij] = std::pair<int, int>(j, i);
                                ++i;
                                ij += j;
                        }
                }
        }
}
 
std::vector<unsigned> powers;
 
template<int dir>
void factor( int num )
{
        while (num != 1) {
                powers[factor_table[num].first] += dir;
                num = factor_table[num].second;
        }
}
 
template<unsigned N>
void calc_combinations(unsigned (&bin_sizes)[N])
{
        using std::swap;
 
        powers.resize(0);
        if (N < 2) return;
 
        unsigned& largest = bin_sizes[0];
        size_t sum = largest;
        for( int bin = 1; bin < N; ++bin ) {
                unsigned& this_bin = bin_sizes[bin];
                sum += this_bin;
                if (this_bin > largest) swap(this_bin, largest);
        }
        fill_sieve(sum);
 
        powers.resize(sum+1);
        for( unsigned i = largest + 1; i <= sum; ++i ) factor<+1>(i);
        for( unsigned bin = 1; bin < N; ++bin )
                for( unsigned j = 2; j <= bin_sizes[bin]; ++j ) factor<-1>(j);
}
 
#include <iostream>
#include <cmath>
int main(void)
{
        unsigned bin_sizes[] = { 8, 1, 18, 19, 10, 10, 7, 18, 7, 2, 16, 8, 5, 8, 2, 3, 19, 19, 12, 1, 5, 7, 16, 0, 1, 3, 13, 15, 13, 9, 11, 6, 15, 4, 14, 4, 7, 13, 16, 2, 19, 16, 10, 9, 9, 6, 10, 10, 16, 16 };
        calc_combinations(bin_sizes);
        char* sep = "";
        for( unsigned i = 0; i < powers.size(); ++i ) {
                if (powers[i]) {
                        std::cout << sep << i;
                        sep = " * ";
                        if (powers[i] > 1)
                                std::cout << "**" << powers[i];
                }
        }
        std::cout << "\n\n";
}
 
  • upload with new input
  • result: Success     time: 0.02s    memory: 2860 kB     returned value: 0

    2**93 * 3**61 * 5**41 * 7**29 * 11**28 * 13**21 * 17**23 * 19**22 * 23**21 * 29**16 * 31**15 * 37**13 * 41**11 * 43**11 * 47**10 * 53**9 * 59**8 * 61**8 * 67**7 * 71**6 * 73**6 * 79**6 * 83**5 * 89**5 * 97**5 * 101**4 * 103**4 * 107**4 * 109**4 * 113**4 * 127**3 * 131**3 * 137**3 * 139**3 * 149**3 * 151**3 * 157**3 * 163**2 * 167**2 * 173**2 * 179**2 * 181**2 * 191**2 * 193**2 * 197**2 * 199**2 * 211**2 * 223**2 * 227**2 * 229**2 * 233**2 * 239**2 * 241**2 * 251 * 257 * 263 * 269 * 271 * 277 * 281 * 283 * 293 * 307 * 311 * 313 * 317 * 331 * 337 * 347 * 349 * 353 * 359 * 367 * 373 * 379 * 383 * 389 * 397 * 401 * 409 * 419 * 421 * 431 * 433 * 439 * 443 * 449 * 457 * 461 * 463 * 467 * 479 * 487