Questions tagged [number-theory]

Number theory is that branch of mathematics that investigates the properties of numbers, typically whole numbers.

Number theory is that branch of mathematics that investigates the properties of numbers, typically whole numbers. Applications include cryptography, error correcting codes, checksums, and programming, since many tasks in programming are made much simpler using modular arithmetic. Key concepts/topics: modular arithmetic, unique factorisation theorem, prime numbers, congruences.

Advanced number theory is better treated on:

419 questions
-3
votes
2 answers

nth non-Fibonacci number

how to find nth non-Fibonacci number in o(logn) non-Fibonacci number are : 4,6,7,9,10.... below function gives non-Fibonacci number for given value of n static int nonFibonacci(int n){ int a=1,b=2,c=3; while(n>0){ a=b; b=c; …
priyank
  • 35
  • 1
  • 1
  • 8
-3
votes
2 answers

Number theory: solution need

Suppose a = a31 a30 . . . a1 a0 is a 32-bit binary word. Consider the 32-bit binary word b = b31 b30 . . . b1 b0 computed by the following algorithm: Scan a from right to left and copy its bits to b until the first 1 is found (which is also…
mystery
  • 360
  • 2
  • 15
-4
votes
2 answers

Is there an integer A such that it has exactly X positive integer divisors and exactly K of them are prime numbers?

I need to determine whether there is an integer A such that it has exactly X positive integer divisors and exactly K of them are prime numbers. We will be given T testcases. e.g T = 1, X = 4 and K = 2 Then we get A = 6 which has exactly 4 factors:…
-4
votes
1 answer

Asking ideas of a codeforces problem (Problem-483A Counterexample)

Problem link: http://codeforces.com/problemset/problem/483/A You need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime. The single line contains two positive…
-4
votes
2 answers

Why is this failing for just a corner case? Question link-https://www.hackerearth.com/problem/algorithm/chandu-and-his-interns/description/#c190148

Why is this failing for just a corner case? Question link-https://www.hackerearth.com/problem/algorithm/chandu-and-his-interns/description/#c190148 It ran fine for all the other cases. I took all the three cases where number of divisors could be…
Reetik Raj
  • 11
  • 2
-4
votes
2 answers

Approach and Code for o(log n) solution

f(N) = 0^0 + 1^1 + 2^2 + 3^3 + 4^4 + ... + N^N. I want to calculate (f(N) mod M). These are the constraints. 1 ≤ N ≤ 10^9 1 ≤ M ≤ 10^3 Here is my code test=int(input()) ans = 0 for cases in range(test): arr=[int(x) for x in…
-4
votes
1 answer

program to get all the combinations of ball-box application

I am new to combination and permutation related algorithms. Does anybody have any thoughts on how to program to solve this classical problem? There are 3 boxes(A,B,C) and 10 balls(1,2,3,...,10), we want to put all balls into the boxes. The result…
daydayup
  • 1,503
  • 4
  • 16
  • 36
-4
votes
1 answer

C++ Number theory: Fastest way to compute max(y = a_i * x+ b_i) <= k

following Problem, when having to make a fast code: I have a list of 2 integers a_i and b_i and I have to compute the equation: y = (a_i * x + b_i), where I'm only interested in y, not in x. All a_i's are prime and different from each other. a_i = y…
-4
votes
3 answers

Java BigInteger , number theory , modular arithmetic

Anyone have an idea on how to implement such a problem in java ? "Implement a subroutine that takes three positive integer arguments (a; b; n) and returns the value of ( (a to the power of b) mod n), where the arguments are represented by about 100…
-4
votes
1 answer

Counting Positive Integers with a Given Number of Divisors

basically what i was trying to do is insert an integer k that represents the number of divisors and then finding all the numbers that have k divisors from 1-100000 #include int main(void) { int k, x = 1, y = 100000, divisor, count; …
Wolf
  • 1
  • 1
-5
votes
1 answer

Extended Euclid Theorem - Can there be more than one pair of x and y for two numbers A and B

GCD(A,B) is Ax + By. So can there be more than one pair of x and y. If yes, how can I find them? I used the following code to find x and y : pair< int , int>* extendedeuclid( int a, int b){ if(b == 0){ pair< int, int>* newpair = new…
Vikas Rathee
  • 59
  • 1
  • 1
  • 9
-5
votes
1 answer

When does the loop terminate in the program because it always has a positive value?

long long fast_exp(long long int base,long long int exp,int p) { int res=1; while(exp>0) { if(exp%2==1) {res=(res*base)%p;} exp=exp>>1; base=(base*base)%p; } return res; } It is a function of modular exponentiation. I want to ask about this while…
kk_00
  • 1
  • 3
-7
votes
1 answer

Big Integer Java

Why is my code printing the output 4 times? The answer is correct but the answer is printed 4 times instead of the desired one time. import java.util.*; import java.math.BigInteger; class THIRTYSEVEN { static Scanner sc = new…
-9
votes
3 answers

This Java program converts a natural number into a set-theoretic encoding using iteration. Request help/strategies for a recursive solution?

I'm trying to get a better understanding of ZFC set theory, in particular how a computer program might model the axiom of infinity to "construct" natural numbers. The typical symbols I've seen used to construct the natural numbers are: "{", "}", and…
1 2 3
27
28