HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > IMPC-2014-15 Questions > problem:


0th-4. 50404 - Sum of Self Powers

IMPC-2014-15 Questions

Start: Nov.22.2014 at 03:00:00 PM
Finish: Nov.22.2014 at 08:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (3)

Contest problems

• 0th-1. 50402 - Hello World!
• 0th-2. 50403 - Number of Chairs
• 0th-3. 50763 - Valid Password
• 0th-4. 50404 - Sum of Self Powers
• 0th-5. 50692 - How much money?
• 1st-2. 50483 - Group Total
• 1st-3. 50484 - Number Of Letters
• 1st-4. 50473 - Counting Circles Posit...
• 1st-6. 50485 - Center of gravity of ...
• 2nd-1. 50522 - Multiplication Table - 2
• 2nd-2. 50512 - Coding redundancy
• 2nd-3. 50533 - Contacts List

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Prepared by : Kristi Dalipaj.

Sum of Self Powers

Question:
A mathematician needs to sum self powers of all the numbers up to n for a problem. Since it would be too much hand work and calculation, he asks for your help in creating a program which does this operation.

To help you, he provides a simplification that for his special formula, he doesn't need to sum all digits but only the last d digits of each n^n;

Question: Write a program to calculate the formula given above for the last d digits of each power.

Input specification
Two integers: n and d which will be given by the user, 1 ≤ n ≤ 10000 and 1 ≤ d ≤ 13.

Output specification
Print the last d digits, if there are 0 in the beginning (f.e 01231321) don't print them but print the rest of the numbers (in the previous example simply print 1231321).

 Sample Input I     Sample Input II   
5 3
10 10
 Sample Output I     Sample Output II   
 413
 405071317

Explanation for Sample Input 1:
     1^1 + 2^2 + 3^3 + 4^4 + 5^5=
     1 + 4 + 27 + 256 + 125 = 413

Для отправки решений необходимо выполнить вход.

www.contester.ru