From 9e28e4c7b67c54229df11d355047ac8a88ea1817 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 15 Dec 2019 15:09:13 +0700 Subject: Normalize pathname --- tht/B/QG-2016/remainder.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tht/B/QG-2016/remainder.scm (limited to 'tht/B/QG-2016/remainder.scm') diff --git a/tht/B/QG-2016/remainder.scm b/tht/B/QG-2016/remainder.scm new file mode 100644 index 0000000..8360da1 --- /dev/null +++ b/tht/B/QG-2016/remainder.scm @@ -0,0 +1,19 @@ +(define (sqr x) (* x x)) +(define (pow x y z) + (cond ((= y 1) (remainder x z)) + ((= (remainder y 2) 0) (remainder (sqr (pow x (quotient y 2) z)) z)) + (else (remainder (* (sqr (pow x (quotient y 2) z)) x) z)))) +(with-output-to-file "REMAINDER.TXT" (lambda () (for-each + (lambda (l) + (let* ((a (integer-expt 10 (string-length (number->string (list-ref l 0))))) + (m (* (list-ref l 2) (- a 1))) + (p (pow a (list-ref l 1) m))) + (display (quotient (remainder (* (list-ref l 0) (- p 1)) m) (- a 1))) + (newline))) + '((12 3 8) (2 15 17) (456 6 1296) (1234 100 9) (11223344 1000000 142857) + (55667788 10000000 1000000007) (1357 24682468 999999999) + (24680 1357913579 777777777) (998 1000000000000 999) + (1234 11111111111111 30) (1 222222222222222 123456789) + (2016 666666666666666 8888888888) (11223344 555666777888999 1357924680) + (999999999999999967 999999999999999877 999999999999999989) + (123456789123456789 123456789123456789 987654321123456789))))) -- cgit 1.4.1