Showing posts with label Volume XII. Show all posts
Showing posts with label Volume XII. Show all posts

Solution of 1230 - MODEX

Problem Description
source:https://uva.onlinejudge.org/external/12/1230.html

Many well-known cryptographic operations require modular exponentiation. That is, given integers x, y and n, compute xy mod n. In this question, you are tasked to program an efficient way to execute this calculation.

Input 

The input consists of a line containing the number c of datasets, followed by c datasets, followed by a line containing the number ‘0’. Each dataset consists of a single line containing three positive integers, x, y, and n, separated by blanks. You can assume that 1 < x, n < 215 = 32768, and 0 < y < 231 = 2147483648

image

Solution of 1225 - Digit Counting

Problem Description
source:https://uva.onlinejudge.org/external/12/1225.html

Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 < N < 10000). After that, he counts the number of times each digit (0 to 9) appears in the sequence. For example, with N = 13, the sequence is: 
                     12345678910111213
 In this sequence, 0 appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and each digit from 4 to 9 appears once. After playing for a while, Trung gets bored again. He now wants to write a program to do this for him. Your task is to help him with writing this program. 

image