BackmediumRecursion TCS

Intergalactic Travel Planner Solution

Problem Statement

Given a positive integer n, find the number of distinct routes a spaceship can take to travel to a planet that is n wormholes away from Earth, where the spaceship can travel either by taking a single wormhole or a pair of wormholes at a time. The number of distinct routes is given by the formula: n + n*(n-1)/2.

Example 1
Input
n = 5
Output
15

Explanation: Step-by-step: with input n = 5, we calculate the number of distinct routes as follows: - Single wormhole routes: 5 - Pair of wormhole routes: 5*(5-1)/2 = 10 - Total distinct routes: 5 + 10 = 15

Example 2
Input
n = 10
Output
55

Explanation: Step-by-step: with input n = 10, we calculate the number of distinct routes as follows: - Single wormhole routes: 10 - Pair of wormhole routes: 10*(10-1)/2 = 45 - Total distinct routes: 10 + 45 = 55

Constraints

  • Input will be a positive integer
  • Input will not exceed 40
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free