Sum of GP

Pages: 12
But i should be from i to n 


I disagree. If I want to know how many people played in just the first round, then i = 1.

But the answer is not the sum of k^1 to k^n.
You can see the example given in the question , the answer should be k^1 to k^n , can you explain how you are satisfying that example ?
The example in the question has three rounds, three questions per round.

But i should be from i to n

When i is one, the answer is not k^1 + k^2 + k^3

The answer is not anything from i to n.

When i is one, the questions is "how many people tried the first question" and the answer is k^3. The answer is not anything involving i from i to n.
Last edited on
No, the answer is 39 which 3^1 + 3^2 + 3^3
When i is one, the questions is "how many people tried the first question" and the answer is k^3.
No, the answer is 39 which 3^1 + 3^2 + 3^3


I disagree.

27 people tried the first question. Not 39.

27 people tried the first question.
9 tried the second.
3 tried the third question.

39 is the number of people who tried the first question, plus the the number of people who tried the second question, plus the number of people who tried the third question.

It seems to me that you keep answering the wrong question. If 27 people answer the first question, how many people answer the first question? 27. I don't know where you get 39 for that answer.
Last edited on
We need to sum the number of people attempting 1st question to the nth question ,the question clearly states this.
It says " task is to determine the sum of total number of players who has attempted ith question for all (1<=i<=N)".


So first answer it for i=1
Then answer it for i=2
Then answer it for i=3
Then answer it for i=4

What else could "for all i" mean?

This question is so badly written. Even the sample answer make no sense; the sample answer doesn't give the sum for all i from one to N. Was the question originally written in English or has it been translated?

Hi anyone got this answer correct ?
@Repeater,

The idea is that in order to ensure that the last answer is answered correctly you need one person per possible answer. That's K people. Therefore you would need K^2 (using ^ for exponentiation) for the second-last question to ensure that K are left for the last question. Therefore you would need K^3 for the third-last question, etc.

So for the given example the answer is 3^3 + 3^2 + 3^1 = 39.

So I agree with the OP's original interpretation of the problem. You need to calculate the sum of a geometric series:

[ K * (K^N - 1) / (K - 1) ] mod 1000000007

Take N = 17, K = 13. Using bc, the answer is:

$ bc<<<'(13 * (13^17 - 1) / (13 - 1))) % 1000000007'
64129164

But the following program gets the wrong answer for N=17, K=13 because the division by K - 1, which would go evenly into the power calculated without the modulus, doesn't go evenly into the power calculated with the modulus.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>

using LL = long long;
const int MOD = 1000000007;

// https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
LL pow_mod(LL base, LL exponent) {
    LL result = 1;
    while (exponent > 0) {
        if (exponent % 2 == 1)
            result = (result * base) % MOD;
        exponent >>= 1;
        base = (base * base) % MOD;
    }
    return result;
}

int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int n, k;
        std::cin >> n >> k;
        if (k == 1)
            std::cout << '1';
        else
            std::cout << (pow_mod(k, n) - 1) / (k - 1) * k % MOD;
            //           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            // if not for the pow_mod modulus, this would divide evenly
        std::cout << '\n';
    }
}

Last edited on
it gives wrong answer
it gives wrong answer

@Wasp, that's what I said. Can't you read? Are you really that stupid? I even said WHY it gives the wrong answer.
@Repeater, just so you know, it wasn't me who "reported" your post. I have no idea why someone would do that. The report button seems mostly meaningless, anyway. Obviously someone is screwing around with it.

As for whether the question was written in English or was translated, I suspect that it was in fact written in English, but by someone whose first language is NOT English.
Last edited on
Topic archived. No new replies allowed.
Pages: 12