int main(int argc, char *argv[]) { int v[128]; int n = 8; /* The initial permutation is 1 2 3 ...*/ int i; for(i = 0; i <= n; i++) v[i] = i + 1; while (next(v,n)) if (is_perm(v,n)) printv(v,n); return 0; }
int main(){ int* phi = new int[LIMIT + 1]; // regular array seg faults for whatever reason for(int i = 0; i <= LIMIT; i++) phi[i] = i; for(int i = 2; i <= LIMIT; i++){ if(phi[i] == i){ for(int j = i; j <= LIMIT; j+=i) phi[j] = phi[j] / i * (i - 1); } } double min = LIMIT; int n = 0; for(int i = 2; i <= LIMIT; i++){ if(is_perm(i, phi[i]) && i / (double)phi[i] < min){ min = i / (double)phi[i]; n = i; } } free(phi); std::cout << n << std::endl; return 0; }
int main() { int end = 10000000; int i = 2; float min = 0; int nmin = 0; for(; i < end; i++) { int t = totient(i); float r = ((float)i) / t; if((r < min || nmin == 0) && is_perm(t, i)) { min = r; nmin = i; } if(i % 1000 == 0) { float pct = ((float)i) / end * 100; printf("%20d %3.2f%%\r", i, pct); fflush(stdout); } } printf("\n%d\n", nmin); return 0; }
// Check for NULL also. inline bool oopDesc::is_perm_or_null() const { return this == NULL || is_perm(); }
PRIVATE type lambda_ty(env bv, type t, frame f) { #ifdef DEBUG if (debug('t')) grind(stdout, "lambda_ty(%x)\n", t); #endif if (t == NULL) panic("lambda_ty"); if (f == arid && is_perm((univ) t)) { /* It's lambda bv . t[NULL] where t is already permanent. This means that t contains no bound vars: return t */ #ifdef DEBUG if (debug('t')) grind(stdout, "Reused type %t\n", t); #endif return t; } switch (t->t_kind) { case GIVENT: /* lambda bv . v[f] -- look for v among the bv's */ return var_rep(bv, t); case TYPEVAR: /* lambda bv . Vi[f] = lambda bv. fi[NULL] */ return lambda_ty(bv, tv_val(t, f), arid); case POWERT: /* lambda bv . (P t)[f] = P (lambda bv . t[f]) */ return mk_power(lambda_ty(bv, t->t_base, f)); case CPRODUCT: { /* lambda bv . (t1 x ... x tn)[f] = (lambda bv . t1[f]) x ... x (lambda bv . tn[f]) */ type a[MAX_ARGS]; int i; if (t->t_nfields > MAX_ARGS) panic("lambda_ty - too many fields"); for (i = 0; i < t->t_nfields; i++) a[i] = lambda_ty(bv, t->t_field[i], f); return mk_cproduct(t->t_nfields, a); } case SPRODUCT: { /* lambda bv . <| x1: t1; ... |>[f] = <| x1: lambda bv. t1[f]; ... |> */ schema s = t->t_schema; int n = s->z_ncomps; schema s1 = alloc_schema(n); int i; for (i = 0; i < n; i++) { s1->z_comp[i].z_name = s->z_comp[i].z_name; s1->z_comp[i].z_type = lambda_ty(bv, s->z_comp[i].z_type, f); } return mk_sproduct(s1); } case MOLECULE: /* lambda bv . (MOLECULE t f')[f] = lambda bv . t[f'] */ return lambda_ty(bv, t->t_mtype, t->t_mframe); case ABBREV: { /* lambda bv . (ABBREV d {t1 t2 ... tn})[f] = ABBREV d {(lambda bv . t1[f]) ... } */ frame p = t->t_params; frame pp = mk_frame(fsize(p)); int i; for (i = 0; i < fsize(p); i++) pp->f_var[i] = lambda_ty(bv, p->f_var[i], f); return mk_abbrev(t->t_def, pp); } default: bad_tag("lambda_ty", t->t_kind); return (type) NULL; } }