# Question on % and prime number

**URL:** <https://discourse.julialang.org/t/question-on-and-prime-number/63107>\
**Category:** New to Julia\
**Created:** [June 17, 2021, 6:09pm UTC](https://discourse.julialang.org/t/question-on-and-prime-number/63107 "2021-06-17T18:09:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daviddoji](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daviddoji/32/26193_2.png) [@daviddoji](https://discourse.julialang.org/u/daviddoji)\
**Post date:** [June 17, 2021, 6:09pm UTC](https://discourse.julialang.org/t/question-on-and-prime-number/63107/1 "2021-06-17T18:09:51Z")

</div>

Hi everyone,  
Julia newbie here 😃 In my attempt to solve the following problem using Julia, which is almost a copy of a solution I came up using Python, I’m obviously not entering in the second while-loop (the println statement shows the ans variable-1).  
Still lot to learn 🙂

```julia
function Problem3()
    #=
    The prime factors of 13195 are 5, 7, 13 and 29.

    What is the largest prime factor of the number 600851475143 ?
    =#

    global ans = 600_851_475_143
    global factor = 2

    while factor * factor < ans
        #println(ans)
        while ans % factor == 0
            ans = ans ÷ factor
            factor += 1
        end
    end

    return ans
end

```

Any help would be appreciated

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 17, 2021, 6:12pm UTC](https://discourse.julialang.org/t/question-on-and-prime-number/63107/2 "2021-06-17T18:12:51Z")

</div>

> [@daviddoji](#):
>
> `while ans % factor == 0`

this is `false` in the first iteration so of course you’re not entering the inner while loop

```julia
julia> 600_851_475_143 % 2
1

```

---

<div class="post-metadata">

**Author:** ![daviddoji](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daviddoji/32/26193_2.png) [@daviddoji](https://discourse.julialang.org/u/daviddoji)\
**Post date:** [June 17, 2021, 6:23pm UTC](https://discourse.julialang.org/t/question-on-and-prime-number/63107/3 "2021-06-17T18:23:21Z")

</div>

OMG, messed up the increment in the outer loop ☹  
Thx!
