Skip to content

Instantly share code, notes, and snippets.

@unvBell
Last active August 29, 2015 14:25
Show Gist options
  • Save unvBell/67bb15b61ddba3e2b98b to your computer and use it in GitHub Desktop.
Save unvBell/67bb15b61ddba3e2b98b to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <initializer_list>
template <int... N>
struct Array {
static void put() {
for(int x : { N... })
printf("%d\n", x);
}
};
template <int M, typename U>
struct Push;
template <int M, int... N>
struct Push<M, Array<N...>> {
using Type = Array<M, N...>;
};
template <int N, int I, int Mod = N%I>
struct Impl {
using Type = typename Impl<N, I+1>::Type;
};
template <int I, int Mod>
struct Impl<1, I, Mod> {
using Type = Array<>;
};
template <int N, int I>
struct Impl<N, I, 0> {
using Type = typename Push<
I, typename Impl<N/I, I>::Type
>::Type;
};
template <int N>
using PrimeDecomposition = typename Impl<N, 2>::Type;
int main() {
PrimeDecomposition<2*3*5*7*11*11*11*13>::put();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment