Walk on the Axis Codechef Solution

Hello Programmers In this post, you will know how to solve the Walk on the Axis Codechef Solution. Problem Code: ANUWTA

Walk on the Axis Codechef Solution
Walk on the Axis Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.


There are N+1 lights. Lights are placed at (0, 0), (1, 0), (2, 0) … (N, 0). Initially all the lights are on. You want to turn off all of them one after one. You want to follow a special pattern in turning off the lights.

You will start at (0, 0). First, you walk to the right most light that is on, turn it off. Then you walk to the left most light that is on, turn it off. Then again to the right most light that is on and so on. You will stop after turning off all lights. You want to know how much distance you walked in the process. Note that distance between (a,0) and (b,0) is |a-b|.


The first line of the input contains an integer T denoting the number of test cases. Each test case has a single integer N on separate line.


For each test case, output the distance you walked.


  • 1 ≤ T ≤ 10^5
  • 1 ≤ N ≤ 10^5


Sample Input 1 


Sample Output 1 


Walk on the Axis CodeChef Solution in JAVA

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int tc = 0; tc < T; tc++) {
			int N = sc.nextInt();
	static long solve(int N) {
		return (long) (N + 1) * (N + 2) / 2 - 1;
© 2021 GitHub, Inc.

Disclaimer: The above Problem (Walk on the Axis) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Tojo hates probabilities Codechef Solution

Leave a Reply

Your email address will not be published. Required fields are marked *