Team Reference Document

Total Page:16

File Type:pdf, Size:1020Kb

Team Reference Document Team Reference Document ACM-ICPC World Finals, 2018 April 15{20, Beijing Contestants: Coach: Filip Bialas doc. Mgr. Zdeněk Dvoøák, Ph.D. Richard Hladík Václav Volhejn Charles University 1 Prologue 1 Treap 6 Link-cut tree 15 trinerdi/base.hpp 1 Counting the number of spanning trees 16 trinerdi/sc.sh 1 Numerical 6 Geometry 16 trinerdi/check.sh 1 Polynomial 6 Binary search 6 Geometric primitives 16 Mathematics (text) 1 Golden section search 6 Point 16 Equations 1 Polynomial roots 6 Line distance 16 Recurrences 1 Determinant 7 Segment distance 16 Trigonometry 2 Linear programming 7 Segment intersection 16 Geometry 2 Linear equations 7 Segment intersection (boolean version) 17 Triangles 2 Linear equations++ 7 Line intersection 17 Quadrilaterals 2 Linear equations in Z 7 2 Point-line orientation 17 Spherical coordinates 2 Matrix inversion 8 Point on segment 17 Derivatives/Integrals 2 FFT 8 Linear transformation 17 Sums 2 Angle 17 Series 2 Number theory 8 Probability theory 2 Fast exponentiation 8 Circles 18 Discrete distributions 2 Primality test 8 Circle intersection 18 Binomial distribution 2 Sieve of Eratosthenes 8 Circle tangents 18 First success distribution 2 Extended Euclid's Algorithm 8 Circumcircle 18 Poisson distribution 2 Modular arithmetic 8 Minimum enclosing circle 18 Continuous distributions 2 Modular inverse (precomputation) 9 Uniform distribution 2 Modular multiplication for ll 9 Polygons 18 Exponential distribution 2 Modular square roots 9 Inside general polygon 18 Normal distribution 3 Discrete logarithm 9 Polygon area 18 Markov chains 3 NTT 9 Polygon's center of mass 18 Number-theoretical 3 Factorization 9 Polygon cut 18 Pythagorean Triples 3 Phi function 10 Convex hull 19 Primes 3 Chinese remainder theorem 10 Polygon diameter 19 Estimates 3 Inside polygon (pseudo-convex) 19 Combinatorics 10 Intersect line with convex polygon (queries) 19 Combinatorial (text) 3 Permutation serialization 10 Misc. Point Set Problems 20 Permutations 3 Derangements 10 Closest pair of points 20 Cycles 3 Binomial coefficient 10 KD tree 20 Involutions 3 Binomial modulo prime 10 Delaunay triangulation 20 Stirling numbers of the first kind 3 Rolling binomial 10 3D point 20 Eulerian numbers 3 Multinomial 10 Polyhedron volume 21 Burnside's lemma 3 3D hull 21 Partitions and subsets 3 Graphs and trees 11 Spherical distance 21 Partition function 3 Bellman{Ford 11 Floyd{Warshall 11 Stirling numbers of the second kind 3 Strings 21 Topological sorting 11 Bell numbers 3 KMP 21 Euler walk 11 Triangles 3 Longest palindrome 21 Goldberg's (push-relabel) algorithm 11 General purpose numbers 3 Lexigographically smallest rotation 21 Min-cost max-flow 11 Catalan numbers 3 Suffix array 21 Edmonds{Karp 12 Super Catalan numbers 4 Suffix tree 22 Min-cut 12 Motzkin numbers 4 String hashing 22 Narayana numbers 4 Globalp min-cut 12 O Aho-Corasick 22 Schr¨odernumbers 4 ( VE) maximum matching (Hopkroft{Karp) 12 O(EV ) maximum matching (DFS) 13 Various 23 Data structures 4 Min-cost matching 13 Bit hacks 23 Order statistics tree 4 General matching 13 Closest lower element in a set 23 Lazy segment tree 4 Minimum vertex cover 13 Coordinate compression 23 Persistent segment tree 4 Strongly connected components 14 Interval container 23 Union-find data structure 4 Biconnected components 14 Interval cover 23 Matrix 5 2-SAT 14 Split function into constant intervals 23 Line container 5 Tree jumps 14 Divide and conquer DP 23 Fast line container 5 LCA 14 Knuth DP optimization 23 Fenwick Tree 5 Tree compression 15 Ternary search 23 2D Fenwick tree 5 Centroid decomposition 15 Longest common subsequence 24 RMQ 6 HLD + LCA 15 Longest increasing subsequence 24 Prologue 67 done Many algorithms in this notebook were taken from the KACTL notebook (with mi- 7d } nor modifications). Its original version is maintained at https://github.com/kth- competitive-programming/kactl. trinerdi/check.sh The sources of this notebook are maintained at https://github.com/trinerdi/icpc- 8a IFS= notebook. Authorship information for each source file and much more can be found bf while read -r a; do there. 83 # Doesn't really work in general (multiline comments are broken, ...), but works well enough f5 printf "%s %s\n" "$(echo "$a" | sed -re 's/\s+|\/\/.*"//g' | md5sum | trinerdi/base.hpp head -c2)" "$a" 67 done 84 #include <bits/stdc++.h> 07 using namespace std; e7 typedef long long ll; Mathematics (text) 5e typedef long double ld; 3e #define rep(i, a, n) for (int i = (a); i < (n); i++) Equations b4 #define per(i, a, n) for (int i = (n) - 1; i >= (a); i--) p de #define FOR(i, n) rep(i, 0, (n)) −b b2 − 4ac ax2 + bx + c = 0 ) x = 2a The extremum is given by x = −b=2a. trinerdi/sc.sh − ec e(){ # run on [problem].in* ed bf ax + by = e x = − f7 t=$(basename `pwd`) ) ad bc 36 if [ "$1" = -d ]; then fl=-g; v=valgrind af − ec cx + dy = f y = 76 else fl=-O2\ -fsanitize=address; v=; fi ad − bc 16 g++ -std=c++11 -lm -Wall -Wno-sign-compare -Wshadow $fl $t.cpp -o $t In general, given an equation Ax = b, the solution to a variable xi is given by c2 for i in $t.in*; do echo $i:; $v ./$t < $i; done 0 7d } det Ai xi = ab create(){ det A 73 for i in {a..z}; do # Change z as needed 0 where Ai is A with the i'th column replaced by b. 15 mkdir "$i" && cd "$i" || continue 16 cp -n ../template.cpp "$i".cpp; touch "$i".in1; cd .. Charles University 2 Recurrences Sums k k−1 If an = c1an−1 + ::: + ckan−k, and r1; : : : ; rk are distinct roots of x + c1x + ::: + ck, cb+1 − ca there are d1; : : : ; dk s.t. ca + ca+1 + ::: + cb = ; c =6 1 n n − an = d1r1 + ::: + dkrk : c 1 Non-distinct roots r become polynomial factors, e.g. a = (d n + d )rn. n(n + 1) n 1 2 1 + 2 + 3 + ::: + n = 2 n(2n + 1)(n + 1) Trigonometry 12 + 22 + 32 + ::: + n2 = 6 n2(n + 1)2 sin(v + w) = sin v cos w + cos v sin w 13 + 23 + 33 + ::: + n3 = 4 cos(v + w) = cos v cos w − sin v sin w 2 − 4 4 4 4 n(n + 1)(2n + 1)(3n + 3n 1) tan v + tan w 1 + 2 + 3 + ::: + n = tan(v + w) = 30 1 − tan v tan w v + w v − w sin v + sin w = 2 sin cos 2 2 Series v + w v − w cos v + cos w = 2 cos cos 2 2 x2 x3 ex = 1 + x + + + :::; (−∞ < x < 1) (V + W ) tan(v − w)=2 = (V − W ) tan(v + w)=2 2! 3! x2 x3 x4 where V; W are lengths of sides opposite angles v; w. ln(1 + x) = x − + − + :::; (−1 < x ≤ 1) 2 3 4 a cos x + b sin x = r cos(x − ϕ) p x x2 2x3 5x4 a sin x + b cos x = r sin(x + ϕ) 1 + x = 1 + − + − + :::; (−1 ≤ x ≤ 1) p 2 8 32 128 2 2 where r = a + b , ϕ = atan2(b; a). x3 x5 x7 sin x = x − + − + :::; (−∞ < x < 1) 3! 5! 7! Geometry x2 x4 x6 cos x = 1 − + − + :::; (−∞ < x < 1) 2! 4! 6! Triangles Side lengths: a; b; c a+b+c Semiperimeter:p p = 2 Probability theory Area: A = p(p − a)(p − b)(p − c) Let X be a discrete random variable with probability pX (x)P of assuming the value x. abc It will then have an expected value (mean) µ = E(X) = xp (x) and variance Circumradius: R = 4A P x X 2 2 2 2 A σ = V (X) = E(X ) − (E(X)) = (x − E(X)) pX (x) where σ is the standard Inradius: r = p x Length of median (divides triangle into two equal-area triangles): deviation. If X is instead continuous it will have a probability density function fX (x) p and the sums above will instead be integrals with pX (x) replaced by fX (x). 1 2 2 2 Expectation is linear: ma = 2b + 2c − a 2 E(aX + bY ) = aE(X) + bE(Y ) s [ ] ( )2 − a For independent X and Y , Length of bisector (divides angles in two): sa = bc 1 b+c 2 2 sin α sin β sin γ 1 V (aX + bY ) = a V (X) + b V (Y ): Law of sines: a = b = c = 2R Law of cosines: a2 = b2 + c2 − 2bc cos α Law of tangents: a + b tan α+β Discrete distributions = 2 a − b α−β tan 2 Binomial distribution The number of successes in n independent yes/no experiments, each of which yields Quadrilaterals success with probability p is Bin(n; p); n = 1; 2;:::; 0 ≤ p ≤ 1. With side lengths a; b; c; d, diagonals e; f, diagonals angle θ, area A and magic flux ( ) 2 2 − 2 − 2 n − F = b + d a c : p(k) = pk(1 − p)n k p k 4A = 2ef · sin θ = F tan θ = 4e2f 2 − F 2 µ = np; σ2 = np(1 − p) ◦ pFor cyclic quadrilaterals the sum of opposite angles is 180 , ef = ac + bd, and A = (p − a)(p − b)(p − c)(p − d). Bin(n; p) is approximately Po(np) for small p. Spherical coordinates First success distribution z The number of trials needed to get the first success in independent yes/no experiments, each of which yields success with probability p, is Fs(p); 0 ≤ p ≤ 1. r y p(k) = p(1 − p)k−1; k = 1; 2;::: 1 1 − p µ = ; σ2 = x p p2 p x = r sin θ cos ϕ r = x2 + y2 + z2 ( p ) Poisson distribution y = r sin θ sin ϕ θ = acos z= x2 + y2 + z2 The number of events occurring in a fixed period of time t if these events occur with a known average rate κ and independently of the time since the last event is Po(λ); λ = tκ.
Recommended publications
  • On Terms of Generalized Fibonacci Sequences Which Are Powers of Their Indexes
    mathematics Article On Terms of Generalized Fibonacci Sequences which are Powers of their Indexes Pavel Trojovský Department of Mathematics, Faculty of Science, University of Hradec Králové, 500 03 Hradec Králové, Czech Republic, [email protected]; Tel.: +42-049-333-2860 Received: 29 June 2019; Accepted: 31 July 2019; Published: 3 August 2019 (k) Abstract: The k-generalized Fibonacci sequence (Fn )n (sometimes also called k-bonacci or k-step Fibonacci sequence), with k ≥ 2, is defined by the values 0, 0, ... , 0, 1 of starting k its terms and such way that each term afterwards is the sum of the k preceding terms. This paper is devoted to the proof of the fact that the (k) t (2) 2 (3) 2 Diophantine equation Fm = m , with t > 1 and m > k + 1, has only solutions F12 = 12 and F9 = 9 . Keywords: k-generalized Fibonacci sequence; Diophantine equation; linear form in logarithms; continued fraction MSC: Primary 11J86; Secondary 11B39. 1. Introduction The well-known Fibonacci sequence (Fn)n≥0 is given by the following recurrence of the second order Fn+2 = Fn+1 + Fn, for n ≥ 0, with the initial terms F0 = 0 and F1 = 1. Fibonacci numbers have a lot of very interesting properties (see e.g., book of Koshy [1]). One of the famous classical problems, which has attracted a attention of many mathematicians during the last thirty years of the twenty century, was the problem of finding perfect powers in the sequence of Fibonacci numbers. Finally in 2006 Bugeaud et al. [2] (Theorem 1), confirmed these expectations, as they showed that 0, 1, 8 and 144 are the only perfect powers in the sequence of Fibonacci numbers.
    [Show full text]
  • Number Systems and Radix Conversion
    Number Systems and Radix Conversion Sanjay Rajopadhye, Colorado State University 1 Introduction These notes for CS 270 describe polynomial number systems. The material is not in the textbook, but will be required for PA1. We humans are comfortable with numbers in the decimal system where each po- sition has a weight which is a power of 10: units have a weight of 1 (100), ten’s have 10 (101), etc. Even the fractional apart after the decimal point have a weight that is a (negative) power of ten. So the number 143.25 has a value that is 1 ∗ 102 + 4 ∗ 101 + 3 ∗ 0 −1 −2 2 5 10 + 2 ∗ 10 + 5 ∗ 10 , i.e., 100 + 40 + 3 + 10 + 100 . You can think of this as a polyno- mial with coefficients 1, 4, 3, 2, and 5 (i.e., the polynomial 1x2 + 4x + 3 + 2x−1 + 5x−2+ evaluated at x = 10. There is nothing special about 10 (just that humans evolved with ten fingers). We can use any radix, r, and write a number system with digits that range from 0 to r − 1. If our radix is larger than 10, we will need to invent “new digits”. We will use the letters of the alphabet: the digit A represents 10, B is 11, K is 20, etc. 2 What is the value of a radix-r number? Mathematically, a sequence of digits (the dot to the right of d0 is called the radix point rather than the decimal point), : : : d2d1d0:d−1d−2 ::: represents a number x defined as follows X i x = dir i 2 1 0 −1 −2 = ::: + d2r + d1r + d0r + d−1r + d−2r + ::: 1 Example What is 3 in radix 3? Answer: 0.1.
    [Show full text]
  • Cheat Sheet of SSE/AVX Intrinsics, for Doing Arithmetic Ll F(Int Ind, Int K) { Return Dp[Ind][K]; } on Several Numbers at Once
    University of Bergen Garbage Collectors Davide Pallotti, Jan Soukup, Olav Røthe Bakken NWERC 2017 Nov 8, 2017 UiB template .bashrc .vimrc troubleshoot 1 tan v + tan w Contest (1) Any possible infinite recursion? tan(v + w) = Invalidated pointers or iterators? 1 − tan v tan w template.cpp Are you using too much memory? v + w v − w 15 lines Debug with resubmits (e.g. remapped signals, see Various). sin v + sin w = 2 sin cos #include <bits/stdc++.h> 2 2 using namespace std; Time limit exceeded: v + w v − w Do you have any possible infinite loops? cos v + cos w = 2 cos cos #define rep(i, a, b) for(int i = a; i < (b); ++i) What is the complexity of your algorithm? 2 2 #define trav(a, x) for(auto& a : x) Are you copying a lot of unnecessary data? (References) #define all(x) x.begin(), x.end() How big is the input and output? (consider scanf) (V + W ) tan(v − w)=2 = (V − W ) tan(v + w)=2 #define sz(x) (int)(x).size() Avoid vector, map. (use arrays/unordered_map) typedef long long ll; What do your team mates think about your algorithm? where V; W are lengths of sides opposite angles v; w. typedef pair<int, int> pii; typedef vector<int> vi; Memory limit exceeded: a cos x + b sin x = r cos(x − φ) What is the max amount of memory your algorithm should need? int main() { Are you clearing all datastructures between test cases? a sin x + b cos x = r sin(x + φ) cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); p 2 2 } Mathematics (2) where r = a + b ; φ = atan2(b; a).
    [Show full text]
  • Composite Numbers That Give Valid RSA Key Pairs for Any Coprime P
    information Article Composite Numbers That Give Valid RSA Key Pairs for Any Coprime p Barry Fagin ID Department of Computer Science, US Air Force Academy, Colorado Springs, CO 80840, USA; [email protected]; Tel.: +1-719-339-4514 Received: 13 August 2018; Accepted: 25 August 2018; Published: 28 August 2018 Abstract: RSA key pairs are normally generated from two large primes p and q. We consider what happens if they are generated from two integers s and r, where r is prime, but unbeknownst to the user, s is not. Under most circumstances, the correctness of encryption and decryption depends on the choice of the public and private exponents e and d. In some cases, specific (s, r) pairs can be found for which encryption and decryption will be correct for any (e, d) exponent pair. Certain s exist, however, for which encryption and decryption are correct for any odd prime r - s. We give necessary and sufficient conditions for s with this property. Keywords: cryptography; abstract algebra; RSA; computer science education; cryptography education MSC: [2010] 11Axx 11T71 1. Notation and Background Consider the RSA public-key cryptosystem and its operations of encryption and decryption [1]. Let (p, q) be primes, n = p ∗ q, f(n) = (p − 1)(q − 1) denote Euler’s totient function and (e, d) the ∗ Z encryption/decryption exponent pair chosen such that ed ≡ 1. Let n = Un be the group of units f(n) Z mod n, and let a 2 Un. Encryption and decryption operations are given by: (ae)d ≡ (aed) ≡ (a1) ≡ a mod n We consider the case of RSA encryption and decryption where at least one of (p, q) is a composite number s.
    [Show full text]
  • Compact Fenwick Trees for Dynamic Ranking and Selection
    Compact Fenwick trees for dynamic ranking and selection Stefano Marchini Sebastiano Vigna Dipartimento di Informatica, Universit`adegli Studi di Milano, Italy October 15, 2019 Abstract The Fenwick tree [3] is a classical implicit data structure that stores an array in such a way that modifying an element, accessing an element, computing a prefix sum and performing a predecessor search on prefix sums all take logarithmic time. We introduce a number of variants which improve the classical implementation of the tree: in particular, we can reduce its size when an upper bound on the array element is known, and we can perform much faster predecessor searches. Our aim is to use our variants to implement an efficient dynamic bit vector: our structure is able to perform updates, ranking and selection in logarithmic time, with a space overhead in the order of a few percents, outperforming existing data structures with the same purpose. Along the way, we highlight the pernicious interplay between the arithmetic behind the Fenwick tree and the structure of current CPU caches, suggesting simple solutions that improve performance significantly. 1 Introduction The problem of building static data structures which perform rank and select operations on vectors of n bits in constant time using additional o(n) bits has received a great deal of attention in the last two decades starting form Jacobson's seminal work on succinct data structures. [7] The rank operator takes a position in the bit vector and returns the number of preceding ones. The select operation returns the position of the k-th one in the vector, given k.
    [Show full text]
  • List of Algorithms
    List of Algorithms Swiss Olympiad in Informatics September 13, 2012 This list contains a few algorithms that may prove useful when solving SOI or IOI related tasks. The current IOI Syllabus can be found here: http://people.ksp.sk/~misof/ioi-syllabus/ioi-syllabus.pdf Please note that this list simply serves as an outline and that tasks are not limited by the algorithms listed below. However, one can also participate (and even be successful) without knowing the algorithms listed below. To guide you better, the most important topics are in bold. • Sorting1 • Binary Search • Data Structures Stack1 Queue1 List: Linked List, Doubly Linked List1 Tree Sets1 and Tree Maps1 (Binary Search Trees) Priority Queue1 Double ended queue1 Binary Heap Data Structure Interval Tree Segment Tree Disjoint{set Data Structure (Union{Find) Rational Numbers Bignum (Addition, Subtraction, Multiplication, Division) Quad Tree optional: Binary Indexed Tree (BIT) (Fenwick Tree) • Graph Algorithms DFS (Depth{First Search) BFS (Breadth{First Search) Connected Components Topological Sorting (toposort) Shortest Path · Dijkstra's Algorithm · Bellman{Ford Algorithm · Floyd{Warshall's Algorithm (all{pairs shortest path) MST (Minimum Spanning Tree) · Kruskal's Algorithm · Prim's Algorithm · Find Articulation Points (articfind) · Hierholzer's Algorithm (for finding Euler cycles) • Dynamic Programming (DP) Prefix Sum Edit Distance LCS (Longest Common Subsequence) LIS (Longest Increasing Subsequence) MCM (Matrix Chain Multiplication) MER (Maximum Empty Rectangle)
    [Show full text]
  • Arxiv:1608.06086V1 [Math.NT]
    POWER OF TWO AS SUMS OF THREE PELL NUMBERS JHON J. BRAVO, BERNADETTE FAYE AND FLORIAN LUCA Abstract. In this paper, we find all the solutions of the Diophantine equation a Pℓ +Pm +Pn =2 , in nonnegative integer variables (n,m,ℓ,a) where Pk is the k-th term of the Pell sequence Pn n≥0 given by P0 = 0, P1 = 1 and Pn+1 =2Pn+Pn−1 for all n 1. { } ≥ MSC: 11D45, 11B39; 11A25 Keywords: Diophantine equations, Pell numbers, Linear forms in logarithm, reduction method. 1. Introduction The Pell sequence P is the binary reccurent sequence given by P = 0, P =1 { n}n≥0 0 1 and Pn+1 = 2Pn + Pn−1 for all n 0. There are many papers in the literature dealing with Diophantine equations≥ obtained by asking that members of some fixed binary recurrence sequence be squares, factorials, triangular, or belonging to some other interesting sequence of positive integers. For example, in 2008, A. Peth˝o[18] found all the perfect powers (of exponent larger than 1) in the Pell sequence. His result is the following. Theorem 1 (A. Peth˝o, [18]). The only positive integer solutions (n, q, x) with q 2 of the Diophantine equation ≥ q Pn = x are (n, q, x) = (1, q, 1) and (7, 2, 13). That is, the only perfect powers of exponent larger than 1 in the Pell numbers are 2 P1 =1 and P7 = 13 . The case q = 2 had been treated earlier by Ljunggren [13]. Peth˝o’s result was rediscovered by J. H.
    [Show full text]
  • Rapid Multiplication Modulo the Sum and Difference of Highly Composite Numbers
    MATHEMATICS OF COMPUTATION Volume 72, Number 241, Pages 387{395 S 0025-5718(02)01419-9 Article electronically published on March 5, 2002 RAPID MULTIPLICATION MODULO THE SUM AND DIFFERENCE OF HIGHLY COMPOSITE NUMBERS COLIN PERCIVAL Abstract. We extend the work of Richard Crandall et al. to demonstrate how the Discrete Weighted Transform (DWT) can be applied to speed up multiplication modulo any number of the form a b where p is small. In ± p ab particular this allows rapid computation modulo numbers of thej form k 2n 1. Q · ± In addition, we prove tight bounds on the rounding errors which naturally occur in floating-point implementations of FFT and DWT multiplications. This makes it possible for FFT multiplications to be used in situations where correctness is essential, for example in computer algebra packages. 1. Introduction In their seminal paper of 1994, Richard Crandall and Barry Fagin introduced the Discrete Weighted Transform (DWT) as a means of eliminating zero-padding when performing integer multiplication modulo Mersenne numbers [2]. While this does not give any improvement in the order of the multiplication, it nevertheless cuts the transform length (and thus time and memory) in half. For these reasons the DWT has become a fixture of the search for Mersenne primes [10]. By using the same form of irrational-base representation as is used for Mersenne numbers, we can in fact eliminate the zero-padding when working modulo a b ± provided that p ab p is sufficiently small that we have enough precision. Essen- tially, as with Mersennej numbers, we choose the base so that the reduction modulo xn 1 implicitQ in the FFT multiplication turns into a reduction modulo a b.
    [Show full text]
  • A Diophantine Equation in K–Generalized Fibonacci Numbers and Repdigits
    A Diophantine equation in k{generalized Fibonacci numbers and repdigits Jhon J. Bravo Departamento de Matem´aticas Universidad del Cauca Calle 5 No 4{70, Popay´an,Colombia E-mail: [email protected] Carlos Alexis G´omezRuiz Departamento de Matem´aticas Universidad del Valle 25360 Calle 13 No 100-00, Cali, Colombia E-mail: [email protected] Florian Luca School of Mathematics University of the Witwatersrand Private Bag X3 Wits 2050 Johannesburg, South Africa Max Planck Institute for Mathematics Vivatsgasse 7 53111 Bonn, Germany Department of Mathematics Faculty of Sciences University of Ostrava 30 Dubna 22 701 03 Ostrava 1, Czech Republic E-mail: [email protected] Abstract 2010 Mathematics Subject Classification: 11B39; 11J86. Key words and phrases: Generalized Fibonacci numbers, lower bounds for nonzero linear forms in logarithms of algebraic numbers, repdigits. 1 2 J. J. Bravo, C. A. G´omezand F. Luca (k) The k−generalized Fibonacci sequence fFn gn starts with the value 0;:::; 0; 1 (a total of k terms) and each term afterwards is the sum of the k preceding terms. In the present paper, we study on members of k{generalized Fibonacci sequence which are sum of two repdigts, extending a result of D´ıazand Luca [5] regarding Fibonacci numbers with the above property. 1 Introduction Given an integer k ≥ 2, we consider the k{generalized Fibonacci sequence (k) (k) or, for simplicity, the k{Fibonacci sequence F := fFn gn≥2−k given by the recurrence (k) (k) (k) (k) (1.1) Fn = Fn−1 + Fn−2 + ··· + Fn−k for all n ≥ 2; (k) (k) (k) (k) with the initial conditions F−(k−2) = F−(k−3) = ··· = F0 = 0 and F1 = 1.
    [Show full text]
  • Arxiv:2008.10398V1 [Math.NT] 24 Aug 2020 Children He Has
    JOURNAL OF THE AMERICAN MATHEMATICAL SOCIETY Volume 00, Number 0, Pages 000{000 S 0894-0347(XX)0000-0 RECURSIVELY ABUNDANT AND RECURSIVELY PERFECT NUMBERS THOMAS FINK London Institute for Mathematical Sciences, 35a South St, London W1K 2XF, UK Centre National de la Recherche Scientifique, Paris, France The divisor function σ(n) sums the divisors of n. We call n abundant when σ(n) − n > n and perfect when σ(n) − n = n. I recently introduced the recursive divisor function a(n), the recursive analog of the divisor function. It measures the extent to which a number is highly divisible into parts, such that the parts are highly divisible into subparts, so on. Just as the divisor function motivates the abundant and perfect numbers, the recursive divisor function motivates their recursive analogs, which I introduce here. A number is recursively abundant, or ample, if a(n) > n and recursively perfect, or pristine, if a(n) = n. There are striking parallels between abundant and perfect numbers and their recursive counterparts. The product of two ample numbers is ample, and ample numbers are either abundant or odd perfect numbers. Odd ample numbers exist but are rare, and I conjecture that there are such numbers not divisible by the first k primes|which is known to be true for the abundant numbers. There are infinitely many pristine numbers, but that they cannot be odd, apart from 1. Pristine numbers are the product of a power of two and odd prime solutions to certain Diophantine equations, reminiscent of how perfect numbers are the product of a power of two and a Mersenne prime.
    [Show full text]
  • On Updating and Querying Submatrices
    On Updating and Querying Submatrices Jason Yang Mentor: Jun Wan MIT PRIMES Computer Science October 19, 2020 Jason YangMentor: Jun Wan On Updating and Querying Submatrices Range update-query problem A is an array of N numbers A range R = [l; r] is the set of indices fijl ≤ i ≤ rg update(R; v): for all i 2 R, set A[i] to A[i] + v query(R): return mini2R A[i] Segment tree + lazy propagation: O(log N) time updates and queries Jason YangMentor: Jun Wan On Updating and Querying Submatrices Generalizations Using different operators update(R; v): 8i 2 R; A[i] A[i] 5 v query(R; v) : return 4i2R A[i] If 5 and 4 are associative, segment tree + lazy propagation usually works (but not always) Ex. (5; 4) = (+; +) (∗; +) ( ; min) This problem and variants have applications in LCA in a tree image retrieval Jason YangMentor: Jun Wan On Updating and Querying Submatrices Generalizations 2 dimensions: the array becomes a matrix ranges fijl ≤ i ≤ rg becomes submatrices [l0; r0][l1; r1] = fijl0 ≤ i ≤ r0g × fjjl1 ≤ j ≤ r1g We call this the submatrix update-query problem. Jason YangMentor: Jun Wan On Updating and Querying Submatrices Previous Work Generalizing segment tree seems to be very difficult update query d = 1 Segment Tree O(log N) O(log N) d = 2 2D Segment Tree O(N log N) O(log2 N) Quadtree O(N) O(N) d = 2, special operator pairs (5; 4) 2D Fenwick Tree (Mishra) O(16 log2 N) O(16 log2 N) 2D Segment Tree (Ibtehaz) O(log2 N) O(log2 N) 2D Segment Tree (ours) O(log2 N) O(log2 N) Jason YangMentor: Jun Wan On Updating and Querying Submatrices Intuition Why is
    [Show full text]
  • A New Algorithm for Updating and Querying Sub-Arrays Of
    A New Algorithm for Updating and Querying Sub-arrays of Multidimensional Arrays Pushkar Mishra Computer Laboratory, University of Cambridge [email protected] Abstract Given a d-dimensional array A, an update operation adds a given constant C to each element within a continuous sub-array of A. A query operation computes the sum of all the elements within a continuous sub-array of A. The one-dimensional update and query handling problem has been studied intensively and is usually solved using segment trees with lazy propagation technique. In this paper, we present a new algorithm incorporating Binary Indexed Trees and Inclusion-Exclusion Principle to accomplish the same task. We extend the algorithm to update and query sub-matrices of matrices (two-dimensional array). Finally, we propose a general form of the algorithm for d-dimensions which d d achieves O(4 ∗ log n) time complexity for both updates and queries. This is an improvement over the previously known algorithms which utilize hierarchical data structures like quadtrees and octrees d−1 and have a worst-case time complexity of Ω(n ) per update/query. Keywords: Algorithm; Data Structure; Multidimensional Array; Binary Indexed Tree; Range-update; Range-query. 1 Introduction The problem of updating and querying sub-arrays of multidimensional arrays is of consequence to sev- eral fields including data management, image processing and geographical information systems. The one-dimensional version of this problem has conventionally been solved using segment trees with lazy propagation technique. We show in this paper that a d-dimensional segment tree (d> 1) supports lazy propagation only along one out of the d dimensions.
    [Show full text]