S3P3 - Arithmetic and Geometric Sequences
An arithmetic sequence goes from one term to the next by always adding (or subtracting) the same value. For instance, 2, 5, 8, 11, 14,... and 7, 3, –1, –5,... are arithmetic, since you add 3 and subtract 4, respectively, at each step. A geometric sequence goes from one term to the next by always multiplying (or dividing) by the same value. So 1, 2, 4, 8, 16,... and 81, 27, 9, 3, 1, 1/3,... are geometric, since you multiply by 2 and divide by 3, respectively, at each step.
The number added (or subtracted) at each stage of an arithmetic sequence is called the "common difference"
The number multiplied (or divided) at each stage of a geometric sequence is called the "common ratio"
Given an integer N you will take N numbers determine whether they form an Arithmetic sequence (and/or) Geometric sequence or not and print their common differnece and common ration
Print -1 if the sequence doesn't form Arithmetic sequence
The same for Geometric sequence
Input
N : number of following integers .. N>1
N integers all integers are from -100 to 100 inclusive
Output
Four lines
the first line contains 1 if the sequence form an arithmetic sequence , 0 if not
the second line contains the common difference , -1 if not forming arithmetic sequence
the first line contains 1 if the sequence form an geometric sequence , 0 if not
the second line contains the common ratio , -1 if not forming geometric sequence
Example
Input: 5
1 2 3 4 5 Output: 1 1
0 -1
Input:
5
16 8 4 2 1
Output:
0 -1
1 2
Input:
5
5 4 3 2 1
Output:
1 1
0 -1
hide comments
|
Min_25:
2014-11-05 06:02:19
@mohamed gamal
|
|
xol odho:
2012-04-02 07:40:22
Is the output four lines? why all examples have just two lines then? Perhaps it should be two lines, each having two integers. |
Added by: | mohamed gamal |
Date: | 2012-01-27 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ASM32-GCC MAWK BC C-CLANG NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |