Description
An arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 … is an arithmetic sequence with common difference of 2.
Here, you are given an arithmetic sequence, where the initial term is ‘a’, the total number of terms in this sequence is ‘n’, and the common difference of successive terms is ‘d’. Then, in this sequence: what is the value of the nth term, and what is the sum of all the terms?
Input
Three integers separated by blanks.
The first integer (a) is the initial term, where -1000
The second integer (n) is the total number of terms in the sequence, where n>=0 and n<1000.
The third integer (d) is the common difference, where -1000
Output
Two values separated by a blank. The first value is the nth term of the sequence, and the second value is the sum of the sequence.
Note that you do not need to print '\n' at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The input contains fifteen different integer numbers, which are 1 to 15 in some random order. Consider, for example, a sequence: 4 3 7 9 15 14 2 1 5 8 11 6 10 12 13. In this sequence, starting from the first place, we get the number 4. It indicates that the next number we need to pick is at the 4th place, which is 9. Likewise, we then go to the 9th place and get the number 5. We repeat this process until we go to a place that has already been visited. In this example, we will stop at the 8th place and get the number 1, because we have found a circle. Therefore, along the way we pick eight numbers, 4 9 5 15 13 10 8 1.
In this problem, you will be given such a sequence of fifteen numbers. Follow the above visiting rule, please
1. get the corresponding sequence of numbers;
2. calculate their sum;
3. convert their decimal representation into hexadecimal representation as the output. For example, the sum of the above instance is 65. Their hexadecimal representation is 41.
Note that we always start from the first place.
Note that, for example, if the sum of these numbers is 95, your hexadecimal number should be 5F.
| decimal | hexadecimal | decimal | hexadecial |
| 0 | 0 | 8 | 8 |
| 1 | 1 | 9 | 9 |
| 2 | 2 | 10 | A |
| 3 | 3 | 11 | B |
| 4 | 4 | 12 | C |
| 5 | 5 | 13 | D |
| 6 | 6 | 14 | E |
| 7 | 7 | 15 | F |
Input
A random sequence of the fifteen different numbers of 1 to 15, which are separated by blanks.
Output
The hexadecimal representation of the sum of the numbers being visited.
Remember to print a '
' at the end of the answer.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given two positive integer sequences {ai} and {bj} (0 < ai, bj < 100), calculate the continued fraction generated by those two sequences.
The continued fraction x is defined as:
.png)
For example, if the sequences {ai} is {2, 7, 3} and {bj} is {3, 2, 2}, then the answer should be 3/(2+ 7/(2 + 2/(3 + 1))) = 5/8
Note that your answer should be expressed in simplest terms. That is, 2/4 should be represented as 1/2. If the answer is an integer then the denominator should be showed as 1. For example, 3 should be represented as 3/1.
Hint:
You may use the following incomplete code to solve the problem:
#includeint a[10], b[10]; int gcd(int a, int b) { /* your code here */ } int main(void) { int i, n; int de, nu; int tmp, g; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &a[i], &b[i]); } nu = 1; de = 1; for (i = 0; i < n; i++) { /* your code here */ } printf("%d %d ", nu, de); return 0; }
Input
The length of the sequence (0
a1 b1
a2 b2
…
an bn
Output
The output is a pair of numerator and denominator, ended with a newline character.