From df9a0d140a7b7edef66f95aa13b5bb4488147f68 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sat, 11 Feb 2017 11:37:48 +0700 Subject: Fast and furiously add others/volume1 --- others/volume1/002.pas | 21 +++++++++ others/volume1/003.pas | 15 +++++++ others/volume1/004.pas | 33 ++++++++++++++ others/volume1/006.pas | 27 ++++++++++++ others/volume1/007.pas | 18 ++++++++ others/volume1/008.pas | 30 +++++++++++++ others/volume1/009.pas | 34 ++++++++++++++ others/volume1/010.pas | 21 +++++++++ others/volume1/012.pas | 28 ++++++++++++ others/volume1/013.pas | 9 ++++ others/volume1/014.pas | 9 ++++ others/volume1/015.pas | 22 +++++++++ others/volume1/017.pas | 9 ++++ others/volume1/018.pas | 11 +++++ others/volume1/020.pas | 32 ++++++++++++++ others/volume1/README.pdf | Bin 0 -> 689259 bytes others/volume1/fibonacci.pas | 103 +++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 422 insertions(+) create mode 100644 others/volume1/002.pas create mode 100644 others/volume1/003.pas create mode 100644 others/volume1/004.pas create mode 100644 others/volume1/006.pas create mode 100644 others/volume1/007.pas create mode 100644 others/volume1/008.pas create mode 100644 others/volume1/009.pas create mode 100644 others/volume1/010.pas create mode 100644 others/volume1/012.pas create mode 100644 others/volume1/013.pas create mode 100644 others/volume1/014.pas create mode 100644 others/volume1/015.pas create mode 100644 others/volume1/017.pas create mode 100644 others/volume1/018.pas create mode 100644 others/volume1/020.pas create mode 100644 others/volume1/README.pdf create mode 100644 others/volume1/fibonacci.pas diff --git a/others/volume1/002.pas b/others/volume1/002.pas new file mode 100644 index 0000000..7732052 --- /dev/null +++ b/others/volume1/002.pas @@ -0,0 +1,21 @@ +uses fibonacci; + +var + m: int64; + i: byte; + +begin + readln(m); + if m <= 2 then + begin + writeln('1 1'); + exit + end; + + for i := 3 to 88 do + if fibonacci93[i] > m then + begin + writeln(i - 1, ' ', fibonacci93[i - 1]); + exit + end +end. diff --git a/others/volume1/003.pas b/others/volume1/003.pas new file mode 100644 index 0000000..a4818da --- /dev/null +++ b/others/volume1/003.pas @@ -0,0 +1,15 @@ +var + n: int64; + l, s: byte; + +begin + readln(n); + l := 0; + s := 0; + repeat + inc(l); + s := s + n mod 10; + n := n div 10 + until n = 0; + writeln(l, ' ', s) +end. diff --git a/others/volume1/004.pas b/others/volume1/004.pas new file mode 100644 index 0000000..caf5142 --- /dev/null +++ b/others/volume1/004.pas @@ -0,0 +1,33 @@ +var + prime: array [2..1000000] of boolean; + i, j, n, k: longint; + b: boolean = true; + +begin + for i := 2 to 1000000 do + prime[i] := true; + for i := 2 to 1000 do + if prime[i] then + for j := i to 1000000 div i do + prime[i * j] := false; + + readln(n, k); + if n < 2 then + writeln('FALSE') + else if n <= 1000000 then + writeln(prime[n]) + else + begin + for i := 2 to trunc(sqrt(n)) do + if n mod i = 0 then + begin + b := false; + break + end; + writeln(b) + end; + for i := 2 to k do + if prime[i] then + write(i, ' '); + writeln +end. diff --git a/others/volume1/006.pas b/others/volume1/006.pas new file mode 100644 index 0000000..989acba --- /dev/null +++ b/others/volume1/006.pas @@ -0,0 +1,27 @@ +var + a, b, g: int64; + c, d: longint; + + +function gcd(x, y: int64): int64; + var + z: longint; + + begin + while y > 0 do + begin + z := y; + y := x mod y; + x := z + end; + gcd := x + end; + + +begin + readln(a, b, c, d); + a := a * d + b * c; + b := b * d; + g := gcd(a, b); + writeln(a div g, ' ', b div g) +end. diff --git a/others/volume1/007.pas b/others/volume1/007.pas new file mode 100644 index 0000000..8a544b2 --- /dev/null +++ b/others/volume1/007.pas @@ -0,0 +1,18 @@ +var + n, i: int64; + a, b, c: smallint; + +begin + readln(n); + a := 1; + b := 1; + i := 2; + while i < n do + begin + c := a; + a := b; + b := (c + a) mod 1000; + inc(i) + end; + writeln(b) +end. diff --git a/others/volume1/008.pas b/others/volume1/008.pas new file mode 100644 index 0000000..2d0f2d0 --- /dev/null +++ b/others/volume1/008.pas @@ -0,0 +1,30 @@ +var + n, d, m, i: byte; + p: qword = 1; + +begin + readln(n); + d := n div 3; + m := n mod 3; + + if n < 3 then + begin + writeln(n); + exit + end; + + if m = 1 then + begin + for i := 2 to d do + p := p * 3; + p := p * 4 + end + else + for i := 1 to d do + p := p * 3; + + if m = 2 then + p := p * 2; + + writeln(p) +end. diff --git a/others/volume1/009.pas b/others/volume1/009.pas new file mode 100644 index 0000000..67f57b1 --- /dev/null +++ b/others/volume1/009.pas @@ -0,0 +1,34 @@ +var + n, i, tmp: longint; + a: array of longint; + +begin + readln(n); + if n > 1 then + setlength(a, trunc(sqrt(n * 2 + 2.25) - 1.5)) + else + setlength(a, 1); + tmp := 0; + for i := 0 to length(a) - 2 do + begin + a[i] := i + 2; + inc(tmp, a[i]) + end; + a[length(a) - 1] := n - tmp; + + if length(a) > 1 then + while a[length(a) - 1] - a[length(a) - 2] > 2 do + for i := length(a) - 1 downto 1 do + begin + tmp := (a[i] - 1 - a[i - 1]) div 2; + if tmp > 0 then + begin + dec(a[i], tmp); + inc(a[i - 1], tmp) + end + end; + + for i in a do + write(i, ' '); + writeln +end. diff --git a/others/volume1/010.pas b/others/volume1/010.pas new file mode 100644 index 0000000..bf8ae90 --- /dev/null +++ b/others/volume1/010.pas @@ -0,0 +1,21 @@ +const + pow5: array[2..25] of qword = (25, 125, 625, 3125, 15625, 78125, 390625, + 1953125, 9765625, 48828125, 244140625, + 1220703125, 6103515625, 30517578125, + 152587890625, 762939453125, 3814697265625, + 19073486328125, 95367431640625, + 476837158203125, 2384185791015625, + 11920928955078125, 59604644775390625, + 298023223876953125); + +var + n, count: qword; + i: byte; + +begin + readln(n); + count := n div 5; + for i := 2 to 25 do + count := count + n div pow5[i] * (i - 1); + writeln(count) +end. diff --git a/others/volume1/012.pas b/others/volume1/012.pas new file mode 100644 index 0000000..79a91ee --- /dev/null +++ b/others/volume1/012.pas @@ -0,0 +1,28 @@ +var + n, i, j: shortint; + pas_tri, pas_tri_old: array of int64; + +begin + readln(n); + setlength(pas_tri_old, n + 1); + pas_tri_old[0] := 1; + pas_tri_old[1] := 0; + setlength(pas_tri, n + 1); + pas_tri[0] := 1; + for i := 1 to n do + pas_tri[i] := 0; + writeln(1); + for i := 1 to n do + begin + write('1 '); + for j := 1 to i - 1 do + begin + pas_tri[j] := pas_tri_old[j] + pas_tri_old[j - 1]; + write(pas_tri[j], ' ') + end; + pas_tri[i] := 1; + writeln(1); + for j := 0 to n do + pas_tri_old[j] := pas_tri[j] + end +end. diff --git a/others/volume1/013.pas b/others/volume1/013.pas new file mode 100644 index 0000000..4884a20 --- /dev/null +++ b/others/volume1/013.pas @@ -0,0 +1,9 @@ +uses fibonacci; + +var + n: shortint; + +begin + readln(n); + writeln(fibonacci93[n + 1]) +end. diff --git a/others/volume1/014.pas b/others/volume1/014.pas new file mode 100644 index 0000000..d3d19c9 --- /dev/null +++ b/others/volume1/014.pas @@ -0,0 +1,9 @@ +uses fibonacci; + +var + n: shortint; + +begin + readln(n); + writeln(fibonacci93[n + 2]) +end. diff --git a/others/volume1/015.pas b/others/volume1/015.pas new file mode 100644 index 0000000..c9928ef --- /dev/null +++ b/others/volume1/015.pas @@ -0,0 +1,22 @@ +var + n, i: smallint; + a: array of longint; + min, min_: longint; + +begin + readln(n); + min := 1000000000; + setlength(a, n); + for i := 0 to n - 1 do + begin + read(a[i]); + if a[i] < min then + min := a[i] + end; + min_ := 1000000000; + for i := 0 to n - 1 do + if (a[i] < min_) and + (a[i] > min) then + min_ := a[i]; + writeln(min, ' ', min_) +end. diff --git a/others/volume1/017.pas b/others/volume1/017.pas new file mode 100644 index 0000000..8c3595f --- /dev/null +++ b/others/volume1/017.pas @@ -0,0 +1,9 @@ +var + c, i: smallint; + +begin + readln(c); + writeln(c div 4); + for i := 0 to c div 4 do + writeln((c - i * 4) div 2, ' ', i) +end. diff --git a/others/volume1/018.pas b/others/volume1/018.pas new file mode 100644 index 0000000..05fd7e9 --- /dev/null +++ b/others/volume1/018.pas @@ -0,0 +1,11 @@ +var + n: int64; + +begin + readln(n); + if (n < 0) or + (sqr(trunc(sqrt(n))) <> n) then + writeln('NO') + else + writeln('YES') +end. diff --git a/others/volume1/020.pas b/others/volume1/020.pas new file mode 100644 index 0000000..4d11bd2 --- /dev/null +++ b/others/volume1/020.pas @@ -0,0 +1,32 @@ +var + n, max, l, h, l0, h0: smallint; + a: array of int64; + +begin + readln(n); + setlength(a, n + 1); + for l := 0 to n - 1 do + read(a[l]); + a[n] := 0; + max := 0; + l := 0; + h := 0; + + l0 := 0; + while l0 < n do + for h0 := l0 to n - 1 do + if a[h0] * a[h0 + 1] >= 0 then + begin + if max < h0 - l0 then + begin + max := h0 - l0; + l := l0; + h := h0 + end; + l0 := h0 + 1; + break + end; + + writeln(l + 1, ' ', h + 1) +end. +end. diff --git a/others/volume1/README.pdf b/others/volume1/README.pdf new file mode 100644 index 0000000..63f6d53 Binary files /dev/null and b/others/volume1/README.pdf differ diff --git a/others/volume1/fibonacci.pas b/others/volume1/fibonacci.pas new file mode 100644 index 0000000..c1bb423 --- /dev/null +++ b/others/volume1/fibonacci.pas @@ -0,0 +1,103 @@ +unit fibonacci; + +interface + const + fibonacci93: array[1..93] of qword = ( + 1, + 1, + 2, + 3, + 5, + 8, + 13, + 21, + 34, + 55, + 89, + 144, + 233, + 377, + 610, + 987, + 1597, + 2584, + 4181, + 6765, + 10946, + 17711, + 28657, + 46368, + 75025, + 121393, + 196418, + 317811, + 514229, + 832040, + 1346269, + 2178309, + 3524578, + 5702887, + 9227465, + 14930352, + 24157817, + 39088169, + 63245986, + 102334155, + 165580141, + 267914296, + 433494437, + 701408733, + 1134903170, + 1836311903, + 2971215073, + 4807526976, + 7778742049, + 12586269025, + 20365011074, + 32951280099, + 53316291173, + 86267571272, + 139583862445, + 225851433717, + 365435296162, + 591286729879, + 956722026041, + 1548008755920, + 2504730781961, + 4052739537881, + 6557470319842, + 10610209857723, + 17167680177565, + 27777890035288, + 44945570212853, + 72723460248141, + 117669030460994, + 190392490709135, + 308061521170129, + 498454011879264, + 806515533049393, + 1304969544928657, + 2111485077978050, + 3416454622906707, + 5527939700884757, + 8944394323791464, + 14472334024676221, + 23416728348467685, + 37889062373143906, + 61305790721611591, + 99194853094755497, + 160500643816367088, + 259695496911122585, + 420196140727489673, + 679891637638612258, + 1100087778366101931, + 1779979416004714189, + 2880067194370816120, + 4660046610375530309, + 7540113804746346429, + 12200160415121876738 + ); + +implementation + +end. -- cgit 1.4.1