program main
    integer::p,ans
    integer(8):: a,b,i
    integer(8), pointer:: cd(:)
    read*, a,b
    allocate(cd(1))
    p=1
    do i = 1, min(a,b)
        if ((mod(a,i) /= 0) .or. (mod(b,i) /= 0))cycle
        if (p > size(cd))then
            call append(cd)
            mp = size(cd)
        end if
        cd(p) = i
        p=p+1
    end do
    p=p-1
    ! print*, cd
    ans=0
    do i=1,p
        if(is_pn(cd(i)))ans=ans+1
    end do


    print*, ans




contains
    subroutine append(arr)
        integer(8), pointer:: arr(:)
        integer(8), pointer:: tmp(:)
        integer:: ns
        ns = size(arr)
        allocate(tmp(ns))
        tmp(1:ns) = arr(1:ns)
        deallocate(arr)
        allocate(arr(2*ns))
        arr(1:ns) = tmp(1:ns)
        return
    end subroutine

    function is_so(x,y) result(ret)
        integer, intent(in):: x,y
        integer:: ii
        logical:: ret

        do ii = 2, min(x,y)
            if (mod(x,ii)==0 .and. mod(y,ii)==0)then
                ret = .false.
                return
            end if
            
        end do

        ret = .true.
        return
        
    end function

    function is_pn(n) result(ret)
        integer(8), intent(in)::n
        integer(8):: i2
        logical:: ret
        do i2=2,n-1
            
            if (mod(n,i2) /= 0) cycle
            
            ret = .false.
            return
         end do
         ret = .true.
         return

    end function
end program