Solution of 10696 - f91

Problem Description
source:https://uva.onlinejudge.org/external/106/10696.html

McCarthy is a famous theorician of computer science. In his work, he defined a recursive function, called f91, that takes as input a positive integer N and returns a positive integer defined as follows:
       • If N ≤ 100, then f91(N) = f91(f91(N + 11)); 
       • If N ≥ 101, then f91(N) = N − 10. 

Write a program, that computes McCarthy’s f91. 

image

Algorithm of 10394 - Twin Primes

Problem Description Link
Algorithm:


This is a simple problem but need more time than other problem.
you can follow this technique .
1. Firstly you need to generate prime in prime[] array up to max=20000000 before getting input.
image

Solution of 10394 - Twin Primes

Problem Description
source:https://uva.onlinejudge.org/external/103/10394.html

Twin primes are pairs of primes of the form (p, p + 2). The term “twin prime” was coined by Paul Stckel (1892-1919). The first few twin primes are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43). In this problem you are asked to find out the S-th twin prime pair where S is an integer that will be given in the input.

Input 

The input will contain less than 10001 lines of input. Each line contains an integers S (1 ≤ S ≤ 100000), which is the serial number of a twin prime pair. Input file is terminated by end of file. 
image

Solution of 483 - Word Scramble

Problem Description
source:https://uva.onlinejudge.org/external/4/483.html

Write a program that will reverse the letters in each of a sequence of words while preserving the order of the words themselves. 

Input 

The input file will consist of several lines of several words. Words are contiguous stretches of printable characters delimited by white space. 

image

Algorithm of 10591 - Happy Number

Problem Description Link
Algorithm:
Iterating this sum-of-squared-digits map always eventually
 reaches one of the 10 numbers 0, 1, 4, 16, 20, 37, 42, 58, 89, or 145
image

Solution of 10591 - Happy Number

Problem Description
source:https://uva.onlinejudge.org/external/105/10591.html

Let the sum of the square of the digits of a positive integer S0 be represented by S1. In a similar way, let the sum of the squares of the digits of S1 be represented by S2 and so on. If Si = 1 for some i ≥ 1, then the original integer S0 is said to be Happy number. A number, which is not happy, is called Unhappy number. For example 7 is a Happy number since 7 → 49 → 97 → 130 → 10 → 1 and 4 is an Unhappy number since 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

Input 

The input consists of several test cases, the number of which you are given in the first line of the input. Each test case consists of one line containing a single positive integer N smaller than 109 .

image

Solution of 10487 - Closest Sums

Problem Description
source:https://uva.onlinejudge.org/external/104/10487.html

Given is a set of integers and then a sequence of queries. A query gives you a number and asks to find a sum of two distinct numbers from the set, which is closest to the query number.

Input 

Input contains multiple cases. 
       Each case starts with an integer n (1 < n ≤ 1000), which indicates, how many numbers are in the set of integer. Next n lines contain n numbers. Of course there is only one number in a single line. The next line contains a positive integer m giving the number of queries, 0 < m < 25. The next m lines contain an integer of the query, one per line. 
      Input is terminated by a case whose n = 0. Surely, this case needs no processing. 

image

Algorithm of 10487 - Closest Sums

Problem Description Link
Algorithm:
To solve this problem you can follow this technique
1. first you need input for n and n integer value
2. then generate all possible sum of n integers
3. then get input for m and m distinct integer query
image

Solution of 10469 - To Carry or not to Carry

Problem Description
source:https://uva.onlinejudge.org/external/104/10469.html

6+9=15 seems okay. But how come 4+6=2? You see, Mofiz had worked hard throughout his digital logic course, but when he was asked to implement a 32 bit adder for the laboratory exam, he did some mistake in the design part. After tracing the design for half an hour, he found his flaw!! He was doing bitwise addition but his carry bit always had zero output. Thus, 

      4 = 00000000 00000000 00000000 00000100 
     +6= 00000000 00000000 00000000 00000110
       --------------------------------------------------------
      2 = 00000000 00000000 00000000 00000010 

Solution of 10008 - What's Cryptanalysis?

Problem Description
source:http://uva.onlinejudge.org/external/100/10008.html

Cryptanalysis is the process of breaking someone else’s cryptographic writing. This sometimes involves some kind of statistical analysis of a passage of (encrypted) text. Your task is to write a program which performs a simple analysis of a given text. 

Input 

The first line of input contains a single positive decimal integer n. This is the number of lines which follow in the input. The next n lines will contain zero or more characters (possibly including whitespace). This is the text which must be analyzed.

image