Robotic Moves
Problem
A
robot's initial position is(0,0) and it can only move along X-axis. It
has N moves to make and in each move, it will select one of the
following options:
1.Go to(X-1,0) from (X,0)
2.Go to(X+1,0) from (X,0)
3.Remain at its current position
Your task is to calculate Σ(abs(X)+abs(Y)) for all reachable(X,Y) .
1.Go to(X-1,0) from (X,0)
2.Go to(X+1,0) from (X,0)
3.Remain at its current position
Your task is to calculate Σ(abs(X)+abs(Y)) for all reachable(X,Y) .
C Solution:
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int t;
- long long int n;
- scanf("%d", &t);
- while(t--)
- {
- scanf("%lld", &n);
- printf("%lld\n", n*(n+1)); // for counting the no. of steps
- }
- }
Note:
We
Are Providing Every Content in this Blog Inspired From Many People and
Provide it Open To All People Who Are Willing Gain Some Stuff in
Computer Science.
Comment Below👇 If You Find Better Solution Than Above Solution.
Post a Comment
Post a Comment
Learn, Share and Enjoy