defcrack(n): guess(str(n/1000000)) less, more, num = check() # print(less, more, num) left = 0 right = 1000000 times = 1 while less != 'true'or more != 'true': times += 1 if less == 'true': left = float(num)*1000000 elif more == 'true': right = float(num)*1000000 else: break num = (left + right) // 2 tmp = num guess(str(num/1000000)) less, more, num = check() # print(less, more, num) return times, tmp
if __name__ == '__main__': l = [500000] whileTrue: # n = 500000*(len(l)+1) - sum(l) # n = min(n, 1000000) # n = max(n, 0) n = 1000000 - sum(l)//len(l) times, num = crack(n) l.append(int(num)) print(times, n, num, sum(l)//len(l)) if times == 1: break print('done')
LaTeX机器人
Level1 我的解法:
1
\newread\myread\openin\myread=/flag1 \read\myread to \fileline\fileline{}
// let main receive a seed intmain(int argc, char *argv[]) { // disable buffering setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0);
unsignedint seed = 1666610168+946; seed = atoi(argv[1]); printf("%u\n",seed); srand(seed-1); int games = 5; int win = 0; int lose = 0; char target[20]; char guess[2000]; for (int i = games; i > 0; i--) { int M = 0; int N = 400000; for (int j = 0; j < N; j++) { double x = rand01(); double y = rand01(); if (x*x + y*y < 1) M++; } double pi = (double)M / N * 4; sprintf(target, "%1.5f", pi); printf("%1.5f\n", pi); } return0; }
然后不难搜得求置换群元素的阶最大的问题可以转化成求一组数的和不超过 $n$ ,如果使这组数的最小公倍数最大的问题。显然这组数应该是互质的,但这并不意味着这组数要全为质数!比如 $n=7$ 时,我们可以得到 $3\times4$ 是最大的, $3$ 和 $4$ 互质,但 $4$ 不是质数。如此我们可以手推几个,然后在数列网站 OEIS 上搜索得到数列A000793,关于这个数列的介绍为 Landau's function g(n): largest order of permutation of n elements. Equivalently, largest LCM of partitions of n. 显然这正是我们要找的,于是复制下面给出的代码就可以生成 $g_1$ 了,而对于 $g_2$ ,我的做法是拿到 $g_2$ 中最大数后面的素数列填充进去,若不能继续填充且空间还有剩余,则使最后两个素数尽可能大且尽可能相近。 最后我的蹩脚算法得出来的界大部分比题目的界要大,有小部分小 $1/10$ 左右,基本上都能大过 $m$ 。
from pwn import * from sage.allimport * from sympy import primerange, prevprime
p = remote("202.38.93 .111", 10114) # context.log_level = "debug" token = <your_token> p.sendlineafter(b"token: ", token.encode()) p.sendlineafter(b"> your choice: ", b"3")
defn2perm(l): ll = [] i = 1 for x in l: ll.append(tuple(range(i, i+x))) i += x return ll
defaupton(N): # compute terms a(0)..a(N) V = [1for _ inrange(N+1)] for i in primerange(2, N+1): for j inrange(N, i-1, -1): hi = V[j] pp = i while pp <= j: hi = max((pp if j == pp else V[j-pp]*pp), hi) pp *= i V[j] = hi return V
defget_fac(n): prod = data[n - 1] f = factor(prod) f_ = str(f).split('*') fl = [] for i in f_: if'^'in i: fl.append(eval(i.replace('^', '**'))) else: fl.append(int(i)) return fl
defget_fac2(n, fl1_prod): fl2 = [] i = 2 whilesum(fl2) < n: if gcd(i, fl1_prod) == 1: fl2.append(i) i += 1 ifsum(fl2) > n: fl2.pop() fl2.pop() fl2.append(prevprime(n - sum(fl2))) return fl2