def era()
  a=Array.new(10001,false)
  ans=[]
  for i in 2..10000
    if !a[i]
      ans.push(i)
      j=i
      while j<=10000
        a[j]=true
        j+=i
      end
    end
  end
  return ans
end

def bin_search(a,n)
  l=0
  r=a.length
  while r-l>0
    t=(r+l)/2
    if a[t]==n
      return true
    elsif a[t]<n
      l=t+1
    else
      r=t
    end
  end
  return false
end

def prime(a,t)
  sum=Array.new(a.length+1,0)
  for i in 0..a.length-1
    sum[i+1]=sum[i]+a[i]
  end
  count=0
  for s in 0..a.length
    b=sum[s..-1]
    if(bin_search(b,t+sum[s]))
      count+=1
    end
  end
  return count
end

a=era()
while true
  t=gets.to_i
  if t==0
    break
  end
  puts prime(a,t)
end
    