45. Fibonacci Series

Acceptance — 0 accepted 0 submissions

Easy
LoopsMath
No companies listed
The Fibonacci series appears in sunflower seeds, pinecones and even ancient Indian poetry (Pingala's work).

The series starts 0, 1 and each next term is the sum of the previous two: 0, 1, 1, 2, 3, 5, 8, …
Print the first N terms.

Input Format
A single integer N.

Output Format
Print the first N terms separated by single spaces.

Constraints
• 1 ≤ N ≤ 50
• Terms can go above 2^31, so use long long or long.

Example 1

Input
7
Output
0 1 1 2 3 5 8

Explanation 0, 1, then 0+1=1, 1+1=2, 1+2=3, 2+3=5, 3+5=8.

Example 2

Input
1
Output
0

Explanation Only the first term.

Example 3

Input
2
Output
0 1

Explanation The first two terms.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
0 1 1 2 3 5 8
No results yet
Run your code to test it against the sample cases.
Problem List