| 1 | #include <assert.h> |
| 2 | #include <stdarg.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #include <pari/pari.h> |
| 7 | |
| 8 | static const char *prog; |
| 9 | |
| 10 | __attribute__((noreturn)) |
| 11 | static void barf(const char *msg, ...) |
| 12 | { |
| 13 | va_list ap; |
| 14 | |
| 15 | va_start(ap, msg); |
| 16 | fprintf(stderr, "%s: ", prog); |
| 17 | vfprintf(stderr, msg, ap); |
| 18 | fputc('\n', stderr); |
| 19 | va_end(ap); |
| 20 | exit(2); |
| 21 | } |
| 22 | |
| 23 | int main(int argc, char *argv[]) |
| 24 | { |
| 25 | GEN n, ff, pp, ee; |
| 26 | long nf; |
| 27 | |
| 28 | prog = argv[0]; |
| 29 | if (argc != 2) { fprintf(stderr, "usage: %s N\n", prog); exit(2); } |
| 30 | pari_init(16ul*1024ul*1024ul, 0); |
| 31 | n = gp_read_str(argv[1]); |
| 32 | if (typ(n) != t_INT || signe(n) <= 0) barf("expected a positive integer"); |
| 33 | sd_factor_proven("1", d_SILENT); |
| 34 | ff = Z_factor(n); |
| 35 | assert(typ(ff) == t_MAT); |
| 36 | assert(lg(ff) == 3); |
| 37 | pp = gel(ff, 1); ee = gel(ff, 2); |
| 38 | assert(typ(pp) == t_COL); |
| 39 | assert(typ(ee) == t_COL); |
| 40 | nf = lg(pp); assert(nf == lg(ee)); |
| 41 | nf--; |
| 42 | while (nf--) { |
| 43 | pp++; ee++; |
| 44 | pari_printf("%Ps %Ps\n", *pp, *ee); |
| 45 | } |
| 46 | return (0); |
| 47 | } |