PARI/GP practice #2

Define the Collatz function c ( n ) c(n) as follows: if n n is even, then c ( n ) = n 2 c(n)=\frac{n}{2} . If it is odd, then c ( n ) = 3 n + 1 c(n)=3n+1 . Let a ( n ) a(n) be the least number of applications of the function c c on n n that is equal to 1 1 . (For example, a ( 3 ) = 8 a(3)=8 since 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 has length 8, and a ( 12 ) = 10 a(12)=10 since 12 -> 6 -> 3 ->... -> 1 has length 10.) Let k k be the concatenation of all positive integers up to and including 1000 1000 (starts 12345... 12345... ). Find a ( k ) a(k) .


The answer is 65834.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Masbahul Islam
Feb 29, 2016

Bill Bell
Dec 15, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def a(n):
    count=1
    while True:
        count+=1
        n=n/2 if n%2==0 else 3*n+1
        if n==1: return count

k=int(''.join([str(i) for i in range(1,1001)]))

print a(k)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...