ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Фёдор Меньшиков. Тренировки > задача:


158. 50404 - Sum of Self Powers

Гость
• Вопросы к жюри (3)

Задачи сборника

• 136. 50443 - Dajte Express
• 147. 50553 - I pjestueshem me 2013
• 148. 50596 - Udhetimi juaj eshte ketu
• 148. 50596 - Udhetimi juaj eshte ketu
• 150. 50763 - Valid Password
• 151. 50560 - Distanca maksimale
• 153. 50368 - Right-most non zero d...
• 155. 50379 - a^b modulus k
• 158. 50404 - Sum of Self Powers
• 30. 50764 - Fast Typing Competition
• 50303 - Pattern
• 50882 - FizzBuzz
• 50308 - IT Knowledge Seminars
• 50320 - Random Sorted List
• 001. 50385 - From m to n
• 002. 50365 - Sum of the numbers f...
• 002. 50452 - Multiplication Table

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
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