Convert one modulus value to other [closed] - math

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
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?

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.

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

Related

Bidirectional assignment operator in R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is there an R function that assigns variables bidirectionally? For example, let <-> represent a bidirectional assignment operator.
a <-> b
a
> b
b
> a
One can define something like:
`%<->%` <- function(x,y){
t <- y
assign(deparse(substitute(y)), x, envir=parent.frame())
assign(deparse(substitute(x)), t, envir=parent.frame())
}
a <- 1
b <- 2
a %<->% b
a
[1] 2
b
[1] 1
Such an operator would not make sense with the way R functions:
From Hadley Wickham's book Advanced R, section "Binding basics":
Consider this code:
x <- c(1, 2, 3)
[...] this code is doing two things:
It’s creating an object, a vector of values, c(1, 2, 3).
And it’s binding that object to a name, x.
So, for instance, when you run:
a <- 1
you are creating a numerical vector with one element and you are binding it to the name a.
a <-> b
would be binding names to one another, which makes no sense in R.
Also note than when you do:
a <- 1
b <- a
b
# [1] 1
You get 1 as the output, not a, because you create another binding (b) to the numerical vector with the value 1. And when you run b, the output is the object binding to it (1), not another name this object is binding to.
Note: Hadley explains all this very clearly with diagrams in his book.

Formula to find square root of a natural number using only addition and subtraction [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
How to use only addition and subtraction to find out square root of a natural number?
Thanks.
[I have looked over the internet but i didn't find any content related to this problem.]
Explanation to my problem: I want to create a c function which will receive only a natural number and return square root of it.
You may say to use the "sqrt" function but i just thought of creating one which will utilize addition and subtraction operator to create the square root.
You don't have to write the program, just writing the formula for it will be just fine. Thanks.
Update: This question is not specifically about coding rather about mathematics.(I tagged "c" as it had some link but this question is NOT about coding.)
n2 is the equivalent of the sum of the n first odd numbers.
You can iterate over the n (consequently adding only the next odd number to the previously calculated sum) until the square is equal or exceeds your number.
k = 0
sum = 0
while sum < target:
k += 1
sum += 2k-1
if sum > target:
the target doesn't have integer root
else:
k is the square root
We can use the fact that (n+1)² = n² + 2n + 1.
def sqrt(n):
k = 0
s = 0
while s <= n:
s = s+k+k+1
k = k+1
return k-1
print (sqrt(0)) # 0^2
print (sqrt(1)) # 1^2
print (sqrt(2)) # (1.4142135623730951...)^2
print (sqrt(144)) # 12^2
print (sqrt(169)) # 13^2
print (sqrt(196)) # 14^2
print (sqrt(255)) # 15^2
print (sqrt(1000)) # (31.622776601683793...)^2
print (sqrt(2000)) # (44.721359549995796...)^2
UPD
Sorry, I thought you were asking for code :)

AB+C when you only have ABC and C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I'm trying to calculate AB+C (A, B and C being boolean values) but I only have the values ABC and C. I can negate, OR, and AND to my heart's content, but I am only getting ABC and C out of the system.
Specifically there is a service that has two boolean state variables. One is a combination of three internal properties and is only true when all three are true, but one of the three state properties is also available. I'm just trying to figure out if I can calculate the value I want without asking for them to add A and B as separate values.
AB is A and B
A + B is A or B
I don't think you can compute AB+C in any case knowing only the value of C and ABC:
If C is true, AB+C is true
If C is false, ABC is false and you can't find out anything about AB.
Old Answer - which is wrong as stated in the comments:
I'll give it a try. You can construct not(not(ABC)+C)+C:
not(not(ABC)+C)+C = not(not(A)+not(B)+not(C)+C))+C
= not(not(A)+not(B))+C
= AB+C

Solving of algebra of the picture [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
i saw this picture over social network
put into equation that will be:
Given:
A=rabit
B=Dog
C=Cat
A+C=10
A+B=20
C+B=24
solve A+B+C = ?
some programming logic? what is your answer?
I do not see any programming logic in this, its just Math.
B + C = 24
-A-C = -20
Adding these two,
B-A = 4
Now taking the 1st equation,
A+B = 10
-A+B = 4
Adding both again
2B= 14
B = 7
Then, A = 3 ( from A+B = 10) and C = 17kgs (from B + C = 24)

Number Theory - Factors, HCF and LCM [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
30, 40 and 'n' are such that every number is a factor of the product of other 2 number. If 'n' is a positive
integer , what is the difference between the maximum value of 'n' and the minimum value of 'n'?
Now, since it says that n is a factor of the product of the other 2 numbers, the max value that n can take is 1200 right?
i guess the hcf will give the minimum value of n
Listing the factors of 30 and 40
30 -> 1,2,3,5,6,10,15,30
40 -> 1,2,4,5,8,10,20,40
hcf(30,40) -> 10
Therfore, the difference is 1200-10 => 1190..
But the answer that is given is 1188...where am i going wrong?
Your approach is wrong. The greatest common divisor of 30 and 40 is not your smallest n.
You are looking for the smallest integer n > 0 that satisfies 40*n = 0 (mod 30) and 30*n = 0 (mod 40).
For the first equation, the result is n_1 = 3. For the second equation, we get n_2 = 4. The smallest n to satisfy both equations is the least common multiple of n_1 and n_2 -- in this case, n = 12.
hcf(30,40) -> 12
30=2*3*5
40=2*2*2*5
So, hcf(30,40) -> 3*2*2=12

Resources