add 06_automation_is_not_enough

This commit is contained in:
2025-09-10 14:10:55 +02:00
parent 8cf5a8a9b4
commit 51722fcecc
3 changed files with 65704 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ json = "0.12.4"
lazy_static = "1.5.0" lazy_static = "1.5.0"
reqwest = { version = "0.12.23", features = ["blocking"] } reqwest = { version = "0.12.23", features = ["blocking"] }
rug = "1.28.0" rug = "1.28.0"
tqdm = "0.8.0"
[lib] [lib]
name = "lib" name = "lib"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,165 @@
#![allow(dead_code)]
use anyhow::Result;
use std::fs::File;
use std::io::{BufRead, BufReader};
use lazy_static::lazy_static;
use rug::ops::MulFrom;
use rug::{Assign, Integer};
use std::ops::Add;
use std::str::FromStr;
use lib::submit;
lazy_static!(
static ref N0: Integer = Integer::from(1001997000002u128);
static ref X0: Integer = Integer::from_str("13361120425250501347832030920224855036595311511513374827901659942687569213067904382419070310529480239935839308518100143939024253857202176158254361885679515473530816156355117821922648901555956036125537445852483998567339002752976575910942962150").unwrap();
static ref N1: Integer = Integer::from(1774734677598263u128);
static ref X1: Integer = Integer::from_str("11593323295292067533341930289979269834079920106030434522240627836294015987043679078861672344892723053626369715841527508395668434915559610809835295347647318767117730544084796074700752732601302352244011354650441946234192592199510139121367920997").unwrap();
static ref N2: Integer = Integer::from(10000000000000000u128);
static ref X2: Integer = Integer::from_str("12451812012967875768280645960359102621677777894853024330321329610110355503343897740935595925071894025774585740051400274576363979250507927352038651542641174781860822343081975931661658111525566916416897092390763978119448659635732847002032508677").unwrap();
static ref M: Integer = Integer::from_str("14004392365098131090160062970945115111185775413941111064876648140973294115502980816410773368597517292734034227298996122159833675150497554142801209096513652073059992938078366061434391648276904643753267405058183481162693381822800709938988762923").unwrap();
static ref E: Integer = Integer::from(65537);
static ref A: Integer = Integer::from_str("1466928606874115117499939299261").unwrap();
static ref B: Integer = Integer::from_str("49119078231137394008451554322").unwrap();
);
fn main() {
let f = faulhaber_equation_from_file("res/faulhaber_coefficient_65537.log").unwrap();
let n: Integer = Integer::from(10000000000000000u128);
let x = (X1.clone() + f(n.clone()) - f(N1.clone())).modulo(&M);
println!("{:?}", x);
println!("{:?}", submit(n, x).unwrap());
// let (mut low, mut high) = (
// Integer::from(1774734677598262u128),
// Integer::from(1774734677598263u128),
// );
// while low != high {
// assert!(low < high);
// let mid: Integer = (high.clone() + low.clone()) / 2;
// let x = (X1.clone() + f(mid.clone()) - f(N1.clone())).modulo(&M);
//
// (low, high) = match submit(mid.clone(), x.clone()) {
// Ok(_) => {
// println!("n = {}", mid);
// println!("x = {}", x);
// (mid, high)
// },
// Err(_) => (low, mid),
// };
// }
}
fn step(mut n: Integer, mut x: Integer, mut temp1: Integer, mut temp2: Integer) -> (Integer, Integer, Integer, Integer) {
n += 1;
let b: &Integer = &B;
// a = pow(n, e, m)
temp1.assign(&n);
let a = temp1.pow_mod(&E, &M).unwrap();
// if (a % A == b) {
temp2.assign(&a);
let c = temp2.modulo(&A);
if c.eq(b) {
// x += x
x *= 2;
}
// x += a
// x %= m
x = x.add(&a).modulo(&M);
(n, x, a, c)
}
fn faulhaber_equation(n: usize) -> impl Fn(Integer) -> Integer {
let coefficients = faulhaber_triangle(n);
for (i, coeff) in coefficients.iter().enumerate() {
println!("{i} = {coeff}");
}
faulhaber_equation_from_coefficients(coefficients)
}
fn faulhaber_equation_from_file(path: &str) -> Result<impl Fn(Integer) -> Integer> {
let mut coefficients = Vec::new();
let file = File::open(path)?;
let reader = BufReader::new(file);
for line in reader.lines() {
coefficients.push(Integer::from_str(&line?)?);
}
println!("{:?}", coefficients.len());
let mut sum = coefficients.iter().fold(Integer::from(0), Integer::add);
sum.modulo_mut(&M);
println!("{:?}", sum);
Ok(faulhaber_equation_from_coefficients(coefficients))
}
fn faulhaber_equation_from_coefficients(coefficients: Vec<Integer>) -> impl Fn(Integer) -> Integer {
move |x| {
let mut result = Integer::from(0);
let mut temp = Integer::from(0);
let mut y = x.clone();
for coeff in coefficients.iter() {
temp.assign(&y);
temp.mul_from(coeff);
result += &temp;
result.modulo_mut(&M);
y *= &x;
y.modulo_mut(&M);
}
result
}
}
fn faulhaber_triangle(n: usize) -> Vec<Integer> {
let neg1 = Integer::from(-1);
let mut inv = Vec::with_capacity(n + 10);
inv.push(Integer::from(0));
for i in 1..n+10 {
inv.push(Integer::from(i).pow_mod(&neg1, &M).unwrap());
}
let mut previous = vec![Integer::from(1)];
for i in tqdm::tqdm(1..=n) {
let mut row = Vec::with_capacity(i + 1);
row.push(Integer::from(0));
let mut sum = Integer::from(1);
for j in 1..=i {
let mut value = (&previous[j - 1]).clone();
value.mul_from(i);
value.modulo_mut(&M);
value.mul_from(&inv[j + 1]);
value.modulo_mut(&M);
sum -= &value;
row.push(value);
}
sum.modulo_mut(&M);
row[0] = sum;
previous = row;
}
previous
}