Beta

Pharaoh's pyramid of sum

Description:

Introduction

Ancient Egypt is thriving! The number of pyramid projects is increasing!
Help the priests to make the right order to the stone quarry, without resorting to the costly ritual of patronage of the goddess Seshat.

Each dynasty of pharaohs built a larger pyramid than before, however, the total height n of the pyramid remains the same.
So have to increase the width: count of blocks for level i of new generation is sum of blocks from levels 0,..,i by previous dynasty.
First dynasty (numbering starts from 1) looks at forerunners


IN & OUT

Function pyramid_cost get:

  • data - integer array of forerunner pyramid: data[i] - count of block's on their level i (0 <= i < n, n < 10^6)
  • k - number of dynasty which pyramid you need calculate: 1 <= k < 10^6
  • p - prime number: n < p < 10^9

You need to return the total number of blocks for pyramid of given dynasty modulo p


Example

IN: data = [a, b, c, d]
    dynasty = 3
    p = 11
    
SOLVE:
   levels   |  0  |     1    |        2      |           3
------------|-----|----------|---------------|---------------------
forerunners |  a  |       b  |            c  |                  d
------------|-----|----------|---------------|---------------------
  I dynasty |  a  |   a + b  |   a +  b + c  |    a +  b +  c + d
 II dynasty |  a  |  2a + b  |  3a + 2b + c  |   4a + 3b + 2c + d
III dynasty |  a  |  3a + b  |  6a + 3b + c  |  10a + 6b + 3c + d
 
OUT: ( (a) + (3a+b) + (6a+3b+c) + (10a+6b+3c+d) ) % 11
Mathematics
Performance

Stats:

CreatedApr 9, 2024
PublishedApr 14, 2024
Warriors Trained27
Total Skips0
Total Code Submissions61
Total Times Completed10
Python Completions10
Total Stars3
% of votes with a positive feedback rating92% of 6
Total "Very Satisfied" Votes5
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Rei_00 Avatar
Ad