number-theory

Factorization of an integer

故事扮演 提交于 2019-12-17 16:31:09
问题 While answering another, I stumbled over the question how I actually could find all factors of an integer number without the Symbolic Math Toolbox . For example: factor(60) returns: 2 2 3 5 unique(factor(60)) would therefore return all prime-factors, "1" missing. 2 3 5 And I'm looking for a function which would return all factors ( 1 and the number itself are not important, but they would be nice) Intended output for x = 60 : 1 2 3 4 5 6 10 12 15 20 30 60 I came up with that rather bulky

Counting Positive Integers with a Given Number of Divisors

送分小仙女□ 提交于 2019-12-14 04:15:11
问题 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 <stdio.h> int main(void) { int k, x = 1, y = 100000, divisor, count; printf("Enter the target number of divisors:\n"); scanf("%d", &k); for (divisor = 0; divisor <= 1; divisor++) if (x % divisor == 0 && y % divisor == 0) count++; printf("There are %d numbers between 1 and 100000 inclusive which have exactly %d divisors\n",

Finding the number of integer partitions given a total, a number of parts, and a maximum summand

你。 提交于 2019-12-12 19:15:02
问题 I'm looking for the number of integer partitions for a total N, with a number of parts S, having a maximum part that is exactly X, without enumerating all of them. For example: all partitions of 100 that have 10 parts and 42 as the largest part. I've found no theorems or partitioning identities that address this question and I suspect that is a non-trivial problem that is not easily derived from known theorems (e.g. Nijenhuis and Wilf 1978, Andrews et al. 2004, Bona 2006): For example: The

Finding perfect numbers (optimization)

≯℡__Kan透↙ 提交于 2019-12-12 10:54:25
问题 I coded up a program in C# to find perfect numbers within a certain range as part of a programming challenge . However, I realized it is very slow when calculating perfect numbers upwards of 10000. Are there any methods of optimization that exist for finding perfect numbers? My code is as follows: using System; using System.Collections.Generic; using System.Linq; namespace ConsoleTest { class Program { public static List<int> FindDivisors(int inputNo) { List<int> Divisors = new List<int>();

Number of positive integers in [1,1e18] that cannot be divided by any integers in [2,10]

白昼怎懂夜的黑 提交于 2019-12-11 17:04:27
问题 I am having difficulty trying to solve the following problem: For Q queries, Q <= 1e6, where each query is a positive integer N, N <= 1e18, find the number of integers in [1,N] that cannot be divided by integers in [2,10] for each query. I thought of using using a sieve method to filter out numbers in [1,1e18] for each query (similar to sieve of eratosthenes). However, the value of N could be very large. Hence, there is no way I could use this method. The most useful observation that I could

What is the time complexity of this algorithm

徘徊边缘 提交于 2019-12-10 13:19:06
问题 Write a program that takes an integer and prints out all ways to multiply smaller integers that equal the original number, without repeating sets of factors. In other words, if your output contains 4 * 3, you should not print out 3 * 4 again as that would be a repeating set. Note that this is not asking for prime factorization only. Also, you can assume that the input integers are reasonable in size; correctness is more important than efficiency. PrintFactors(12) 12 * 1 6 * 2 4 * 3 3 * 2 * 2

Why does array size have to be 3^k+1 for cycle leader iteration algorithm to work?

一个人想着一个人 提交于 2019-12-09 12:28:34
问题 The cycle leader iteration algorithm is an algorithm for shuffling an array by moving all even-numbered entries to the front and all odd-numbered entries to the back while preserving their relative order. For example, given this input: a 1 b 2 c 3 d 4 e 5 the output would be a b c d e 1 2 3 4 5 This algorithm runs in O(n) time and uses only O(1) space. One unusual detail of the algorithm is that it works by splitting the array up into blocks of size 3 k +1. Apparently this is critical for the

Converting from a string to a number

依然范特西╮ 提交于 2019-12-07 19:23:16
问题 So, I am trying to write a program to decode 6-character base-64 numbers. Here is the problem statement: Return the 36-bit number represented as a base-64 number in reverse order by the 6-character string s where the order of the 64 numerals is: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-+ i.e. decode('000000') → 0 decode('gR1iC9') → 9876543210 decode('++++++') → 68719476735 I would like to do this WITHOUT strings. The easiest way to do this would be to create the inverse

Getting a list of square-free numbers

落花浮王杯 提交于 2019-12-07 11:02:39
问题 One way to get that is for the natural numbers (1,.., n ) we factorise each and see if they have any repeated prime factors, but that would take a lot of time for large n . So is there any better way to get the square-free numbers from 1,.., n ? 回答1: You could use Eratosthenes Sieve's modified version: Take a bool array 1.. n ; Precalc all squares that are less than n; that's O(sqrt(N)); For each square and its multiples make the bool array entry false... 回答2: From http://mathworld.wolfram

How to find total number of divisors upto N?

坚强是说给别人听的谎言 提交于 2019-12-06 16:34:12
Given a number N, have to find number the divisors for all i where i>=1 and i<=N. Can't figure it out.Do I have to this using prime factorization? Limit is N<=10^9 Sample Output: 1 --> 1 2 --> 3 3 --> 5 4 --> 8 5 --> 10 6 --> 14 7 --> 16 8 --> 20 9 --> 23 10 --> 27 11 --> 29 12 --> 35 13 --> 37 14 --> 41 15 --> 45 To compute much faster, use the following Pseudocode: sum = 0; u = floor(sqrt(N)); foreach k <= u, sum += Floor(N / K); sum = 2*sum-u*u The above formula is given by Peter Gustav Lejeune Dirichlet in 19th Century. I have written a C program using above algorithm and it takes 0.118