Questions tagged [division]
for a challenge involving the mathematical operator of division or integer division
50 questions
20
votes
25
answers
2k
views
Divmod continuously until the remainder is 1 or 0, then get the remainder
The task is simple, divide, get the quotient and the remainder, and if the remainder isn't 1 or 0, do the same thing (quotient divmod remainder) until the remainder is 1 or 0, then get the remainder. ...
15
votes
2
answers
2k
views
Find the magic numbers to divide a number without division
An integer \$x\in[0,2^{32}-1]\$ divided by an integer \$d\in{[1,2^{31}]}\$ will produce an integral quotient \$q\$ and a remainder \$r\$, so that \$x=d\times q+r\$.
Any \$q\$, in fact, can be ...
26
votes
8
answers
2k
views
Implement Ash's float division
Ash has a bit of an interesting float division algorithm. It's designed to never return NaN, and things like signed zero and infinity need to be handled.
How it ...
29
votes
34
answers
2k
views
Semidivisibility
NOTE: Some terminology used in this challenge is fake.
For two integers n and k both greater than or equal to 2 with ...
4
votes
1
answer
230
views
Is it a Self-divisor? [duplicate]
Task
Write a function or program that takes n as a parameter and prints the first n self-divisors.
Definition of Self-divisor
A ...
-6
votes
5
answers
227
views
Report divisibility with arithmetic integer operations only [closed]
Given two numbers, the first is greater than the second, check whether the first number is divisible by the second without a remainder. If divisible, answer "yes"(...
7
votes
16
answers
762
views
Extract and Divide
Challenge
For a given positive integer \$n\$:
Repeat the following until \$n < 10\$ (until \$n\$ contains one digit).
Extract the last digit.
If the extracted digit is even (including 0) multiply ...
8
votes
2
answers
359
views
Integer Division Loops
Challenge
Given any positive integer supported by your language:
Take the input and divide it into two halves. For all divisions in this program, if the input is odd, round one half up and one half ...
10
votes
3
answers
297
views
Form a list using prime numbers
You have been given N piles of coins. You have decided to divide each of those B1, B2, ..., BN piles among separate groups of people. The amount of people receiving coins has to be a prime number and ...
14
votes
24
answers
2k
views
Calculate the Upper Divmod
Task
Given two positive integers (dividend and divisor), calculate the quotient and the remainder.
Normally it would be calculated as e = o*q+r where ...
28
votes
70
answers
4k
views
Find the sum of the divisors of N
Write a program that displays on the screen the sum of the divisors of a number (1 ≤ N ≤ 100) entered by the user in the range of 1 to N.
This is OEIS A000203.
Examples:
Input: 7
...
21
votes
21
answers
4k
views
Fold the integer to save space!
The crazy mathematician owns a wide collection of numbers, and therefore the space he has left is quite limited. To save some, he must fold his integers, but unfortunately he is really lazy. Your task,...
26
votes
49
answers
2k
views
Product of Divisors
Challenge
Given a positive integer, return the product of its divisors, including itself.
This is sequence A007955 in the OEIS.
Test Cases
1: 1
2: 2
3: 3
4: 8
5: 5
6: 36
7: 7
8: 64
9: 27
10: 100
12:...
23
votes
45
answers
2k
views
Proper Divisor mash-up
A proper divisor is a divisor of a number n, which is not n itself. For example, the proper divisors of 12 are 1, 2, 3, 4 and 6.
You will be given an integer x, x ≥ 2, x ≤ 1000. Your task is to sum ...
15
votes
20
answers
1k
views
Sum my Fibonaccified divisors!
The famous Fibonacci sequence is F(0) = 0; F(1) = 1; F(N+1) = F(N) + F(N-1) (for this challenge we are beginning with 0).
Your challenge: Given n, output the sum ...
51
votes
104
answers
6k
views
Division and remainder
This challenge, while probably trivial in most "standard" languages, is addressed to those languages which are so esoteric, low-level, and/or difficult to use that are very rarely seen on this site. ...
18
votes
22
answers
2k
views
Division of not so little numbers
Write a program or function that takes in positive integers a, b and c, and prints or ...
43
votes
117
answers
7k
views
Divisibility test
Task
Given two strictly positive integers n and d as input, determine whether n is evenly divisible by d, i.e., if there exists an integer q such that n = qd.
You ...
32
votes
31
answers
5k
views
Implement the divisibility-by-7 rule
To check whether a decimal number is divisible by 7:
Erase the last digit. Multiply it by 2 and subtract from what is left. If the result is divisible by 7, the original number is divisible by 7.
(...
31
votes
6
answers
2k
views
Have you been nice this year?
Introduction
Santa has too many names to process, and needs your help! He needs you to write a program or a function, which outputs nice, ...
16
votes
4
answers
534
views
Calculate A(N) / B(N) with C(N) digits
Consider three number sequences, \$A\$, \$B\$ and \$C\$:
\$A\$: A sequence based on recurrence relations, \$f(n) = f(n-1)+f(n-2)\$, starting with \$f(1) = 3, f(2) = 4\$. So, the sequence begins like ...
25
votes
6
answers
3k
views
Closest fraction
Task:
Your program is given a proper, positive simple fraction in the format <numerator>/<denominator>.
For this input, it must find two fractions.
A ...
16
votes
9
answers
2k
views
Implement arbitrary precision division
Implement a function divide(int a, int b, int c) that prints the base 10 value of a/b. without using any floating point math nor ...
49
votes
66
answers
12k
views
Divide a number by 3 without using *, /, +, -, % operators [closed]
Quoting this question on SO (Spoiler alert!):
This question has been asked in an Oracle interview.
How would you divide a number by 3 without using *, /, +, -, %,
operators?
The number ...
22
votes
5
answers
2k
views
Visualize long division with ASCII art
Write a program that visualizes long division with ASCII art. Input consists of two integers, a numerator and a denominator, using the input format of your choice.
Examples:
1234 ÷ 56:
<...