Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:04:25+00:00 2026-06-01T04:04:25+00:00

I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I

  • 0

I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I want idea (only small approach/hint)to solve this problm efficienty,so plz help me.!
Here Is the problem Statement::

Suppose there are two rabbits,named rabbit foo and rabbit bar.Initially both of them are located at the origin(center) facing each others.

Foo knows jump of only two lengths m,n.That is foo can jump either m length to his left or m length to his right or n length to his left or n length to his
right side in a single attempt.

Similarly bar also knows jump of only two lengths-p,q.That is bar can jump either p length to his left or p length to his right or q length to his left or q length to his
right side in a single attempt.

Now the master of these two rabbits want to place himself exactly at one point such that both of the rabbits will be able to reach his master in one or more attempts.
Also ,the master place himself at most L lengths away from the origin.
We have to calculate At how many position the master can place himself.

m,n,p,q and L are very large ,as larger as 10^17.

So how to solve it efficiently.

Example::

m=1 n=2

m=4 n=5

L=1

answer=3;

As

Foo can jumps 2 length to his right side and after that one length to his left side.

Bar can jumps 5 lengths to his rgt and after that four lenth to his left side.

to reach his master who is place 1 units away from the origin.

Foo 2 length left and after that one length right side.
Bar 5 length left and 5 length rgt to reach his master who located himself at 1 length away from origin

Master can also place himself at the origin since both foo and bar would be able to reach his master in two moves
so total positions=3.

Other Examples::

m=2 n=4

p=3 q=6

L=7

answer=3.

m=10 n=12

p=3 q=9

answer=5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:04:25+00:00Added an answer on June 1, 2026 at 4:04 am

    Foo can reach any position that is a multiple of gcd(m,n) and only those. Bar can reach the positions that are multiples of gcd(p,q), so the positions reachable by both are exactly the multiples of lcm(gcd(m,n),gcd(p,q)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am solving this problem of rotating an array and got algorithm and code
I was practicing the dynamic programming problem on SPOJ. But I have no idea
I'm practising python and recently this problem crept up when I have invalid syntax
I'm practising on threading and came across this problem. The situation is like this:
I was practicing the problem on Algorithm games , I tried the following problem
I was practicing SRM Problems in Topcoder.I came across this problem Problem Statement: Today
I'm practising POSIT algorithm in OpenCV, following the tutorial http://opencv.willowgarage.com/wiki/Posit My goal is to
I'm practising a bit on JSP and want to create a simple formular field.
Hello i'm practising C and i have a little problem with the following code.
I'm not looking to copy a qsort algorithm. I'm practicing writing qsort and this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.