-1
A = 2548788451252366445785585474844745854781554558547847844

B = 50135928365972237608005364328936872115615930177019003323815

x is unknown 

Given A and B find C, where C must be the nearest integer to A that goes into B x times.

Note: C must be smaller than A or equal with A.

Calculating C manually will involve subtracting or dividing A from B x times until we get near A and therefore to C.

Is there a formula or maybe a SageMath or PARI method to calculate C?

Thanks.

Robert
  • 117

1 Answers1

1

You can just divide $B$ by $x$, then round down to the next whole number. Any language that lets you handle integers this large will do that. $A$ does not figure in this at all.

Based on the comment you are just asking for the remainder of the division of B by A. Many languages have a modulo operator which will do this. Often it is the percent sign, so you would write $C=B\%A$ You can do division with remainder in any language that can handle large integers. If you can't do the modulo operation, you can do integer division and $C=B-\lfloor B/A\rfloor\cdot A$

Ross Millikan
  • 374,822
  • Thanks, but [x] is unknown so I cannot use this method. I will update the question to mention this fact. – Robert Jan 07 '21 at 15:04
  • Then what are you trying to answer? Are you actually looking for a number that divides $B$ exactly? You should say that. – Ross Millikan Jan 07 '21 at 15:06
  • I'm looking for the closest number to A that goes into B x times. I don't know x because if I knew that this would have been a simple task to answer. – Robert Jan 07 '21 at 15:31
  • Yes, you said that. Do you mean it has to divide exactly? Otherwise it doesn't give any information to say "goes into $B\ x$ times" without knowing $x$ – Ross Millikan Jan 07 '21 at 15:33
  • 1
    The division is most certainly not exact. There will be remainders. But if we substract let's say A from B many times we will eventually get to a C number that's closest to A. Doing this manually with large numbers is very difficult. Hope it makes sense. – Robert Jan 07 '21 at 15:37
  • So with smaller numbers: if A=111 and B=570 then we do 570-111-111-111-111-111=15

    C=15 in this case.

    Not sure if I've explained correctly in the question but this number 15 is the nearest to 111 that is not larger than 111. Maybe I am looking for a remainder but not sure if it's possible to calculate with larger numbers.

    – Robert Jan 07 '21 at 17:13