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

Solution of 382 - Perfection

Problem Description
source: https://uva.onlinejudge.org/external/3/382.html

From the article Number Theory in the 1994 Microsoft Encarta: “If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not ±1, b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant.” 

     Your task is: Given a number, determine if it is perfect, abundant, or deficient. 

image

Solution of 374 - Big Mod

Problem Definition
source: https://uva.onlinejudge.org/external/3/374.html

Calculate 
                                                                  R := B P 
mod M for large values of B, P, and M using an efficient algorithm. (That’s right, this problem has a time dependency !!!.)

Input 

The input will contain several test cases, each of them as described below. Consecutive test cases are separated by a single blank line. 
     
    Three integer values (in the order B, P, M) will be read one number per line. B and P are integers in the range 0 to 2147483647 inclusive. M is an integer in the range 1 to 46340 inclusive.

image

371 - Ackermann Functions

Problem description:
source: https://uva.onlinejudge.org/external/3/p371.html

An Ackermann function has the characteristic that the length of the sequence of numbers generated by the function cannot be computed directly from the input value. One particular integer Ackermann function is the following:

This Ackermann has the characteristic that it eventually converges on 1. A few examples follow in which the starting value is shown in square brackets followed by the sequence of values that are generated, followed by the length of the sequence in curly braces:

    [10] 5 16 8 4 2 1 {6}
    [13] 40 20 10 5 16 8 4 2 1 {9}
    [14] 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 {17}
    [19] 58 29 88 44 22 ... 2 1 {20}
    [32] 16 8 4 2 1 {5}
    [1] 4 2 1 {3}