In [ ]:
@time sol357(10^8)

In [128]:
function lotdivs(lim :: Int)
    refs :: Array = Array(Array,lim)
    for i = 1:lim
        refs[i] = [1]
    end
    llim :: Int = isqrt(lim)
    for i = 2:lim
        for j = i*i:i:lim
            push!(refs[j],i)
        end
    end
    refs
end


Out[128]:
lotdivs (generic function with 1 method)

In [1]:
function sol357(lim::Int)
    llim2 :: Int = isqrt(1+lim)
    pref :: Array = trues(1+lim)
    for i = 3:2:llim2
        if pref[i]
            for j = i*i:i*2:1+lim
                pref[j] = false 
            end
        end
    end
    refs :: Array = Array(Array,lim)
    for i = 1:lim
        refs[i] = [1]
    end
    llim :: Int = isqrt(lim)
    for i = 2:llim
        for j = i*i:i:lim
            push!(refs[j],i)
        end
    end
    res :: Int = 0
    for i = 1:lim
        if 0 == rem(i,10000)
            println(i)
        end
        ember = true
        for r in refs[i]
            tmp = r + div(i,r)
            if iseven(tmp)
                ember = false
                break
            elseif !pref[tmp]
                ember = false
                break
            end
        end
        if ember
            res += i
        end
    end
    res
end


Out[1]:
sol357 (generic function with 1 method)

In [100]:
function rtprimes(lim :: Int)
    start :: Array = [[2],[3],[5],[7]]
    bahan :: Array{Int} = [1,3,7,9]
    while true 
        for s in start
            tmp = s
            for b in bahan
                
end


Out[100]:
rtprimes (generic function with 1 method)

In [85]:
function isharshad(n :: Int)
    0 == rem(n,sum(numcol(n)))
end


Out[85]:
isharshad (generic function with 1 method)

In [81]:
sum(digits(123423432))


Out[81]:
24

In [77]:
for i = 1:5 
    @time res = sol429(10^8)
    print(res, "  ")
end


elapsed time: 2.06363794 seconds (246719472 bytes allocated, 1.33% gc time)
22632818  elapsed time: 2.125575371 seconds (246719424 bytes allocated, 1.13% gc time)
22632818  elapsed time: 2.061061345 seconds (246719424 bytes allocated, 1.13% gc time)
22632818  elapsed time: 2.292630082 seconds (246719440 bytes allocated, 1.01% gc time)
22632818  elapsed time: 2.284224624 seconds (246719424 bytes allocated, 1.14% gc time)
22632818  

In [70]:
function sol429(lim :: Int)
    modi :: Int = 1000000009
    refs :: Array{Bool} = trues(lim)
    llim :: Int = isqrt(lim)
    for i = 3:2:llim
        if refs[i]
            for j = i*i:2*i:lim
                refs[j] = false 
            end
        end
    end
    res = [powermod(2,maxexpt(2,lim),modi)]
    for i = 3:2:lim
        if refs[i]
            push!(res,powermod(i,maxexpt(i,lim),modi))
        end
    end
    muls :: Int = 1
    for r in res 
        muls = modmul(muls,1+(r^2),modi)
    end
    muls
end


Out[70]:
sol429 (generic function with 1 method)

In [67]:
function modmul(a :: Int,b :: Int,modi :: Int)
    rem(a*b,modi)
end


Out[67]:
modmul (generic function with 1 method)

In [73]:
sol429(factorial(4))


Out[73]:
715711976

In [74]:
function maxexpt(p :: Int, lim::Int)
    i :: Int = 1
    res :: Int = 0
    while true 
        tmp = p^i
        if tmp > lim
            return res
        else 
            res += div(lim,tmp)
        end
        i += 1
    end
end


Out[74]:
maxexpt (generic function with 1 method)

In [19]:
function uniDivisors(n::Int)
    lim :: Int = isqrt(n)
    res :: Array{Int} = Int[]
    for i = 1:lim
        if 0 == rem(n,i)
            divs :: Int = div(n,i)
            if 1 == gcd(divs,i)
                push!(res,i)
                push!(res,divs)
            end
        end
    end
    res
end


Out[19]:
uniDivisors (generic function with 1 method)

In [14]:
function prodmod(xs :: Array{Int}, modi::Int)
    res :: Int = 1
    for x in xs 
        res = rem(x*res,modi)
    end
    res
end


Out[14]:
prodmod (generic function with 1 method)

In [6]:
function fakmod(n :: Int, modi :: Int)
    res :: Int = 1
    for i = 2:n
        res = rem(res*i,modi)
    end
    res
end


Out[6]:
fakmod (generic function with 1 method)

In [31]:



Out[31]:
1-element Array{Int64,1}:
 512

In [36]:



Out[36]:
sol429 (generic function with 1 method)

In [1]:
include("Common.jl")


Out[1]:
ispsqr (generic function with 1 method)

In [3]:
function testi(f,input)
    for i = 1:10
        @time res = f(input)
        println(res)
    end
end


Out[3]:
testi (generic function with 1 method)

In [88]:
function sumsieve(lim::Int)
    refs :: Array{Bool}, res :: Int , llim :: Int = trues(lim), 2, isqrt(lim)
    for i = 3:2:llim 
        if refs[i]
            for j = i*i:2*i:lim 
                refs[j] = false 
            end
            res += i
        end
    end
    num :: Int = 0 == rem(llim,2) ? llim+1 : llim + 2
    for i = num:2:lim
        if refs[i]
            res += i
        end
    end
    return res 
end


Out[88]:
sumsieve (generic function with 1 method)

In [1]:
include("Common.jl")


Out[1]:
ispsqr (generic function with 1 method)

In [ ]: