-3

Given N = A%B, how to find the value of A%C , where B > C. You are given value of N and C, but not of A.

Is there any way to find this?

Scott Mermelstein
  • 15,174
  • 4
  • 48
  • 76
chao
  • 9
  • 6

2 Answers2

7

Nope. Consider the following:

A = 19
B = 10
C = 7
==> Given 9, you should get 5.

A = 29
B = 10
C = 7
==> Given 9, you should get 1.

So given the same input, there may be multiple answers.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
1

The modulo operation is one-way: given a mod b = n, all I can say is that a comes from the set of all other integers which, modulo b, equal n.

Let's demonstrate that this is impossible in general, taking B=3, C=2.

  • n = a mod 3 = 1
  • => a is in the set of integers {3x + 1}
  • so consider, x=1
    • 4 mod 3 = 1, so that works
    • 4 mod 2 = 0
  • now consider x=2
    • 7 mod 3 = 1, so we can't distinguish 4 from 7 knowing only n and b
    • 7 mod 2 = 1

That is, given b=3 and n=1, you'd have to get two different answers without knowing a.

However, you may consider it's a special case that b and c here are coprime, and in fact are both prime. You can certainly solve this easily for some cases, such as b=4 and c=2.

BTW, further discussion on this is probably better suited to mathoverflow

Community
  • 1
  • 1
Useless
  • 64,155
  • 6
  • 88
  • 132