UVA-1644 - Prime Gap

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
  • 本題選為「20161220 大學程式能力檢定 CPE」題目。

題意概要

題目給定一個數字 ,請求出最接近這個數字 的兩個質數間距有幾個數字,若該數字 為質數,則輸出 0


Input

The input is a sequence of lines each of which contains a single positive integer. Each positive integer is greater than and less than or equal to the 100000th prime number, which is . The end of the input is indicated by a line containing a single zero.


Output

The output should be composed of lines each of which contains a single non-negative integer. It is the length of the prime gap that contains the corresponding positive integer in the input if it is a composite number, or 0 otherwise. No other characters should occur in the output.


Sample Input

10
11
27
2
492170
0

Sample Output

4
0
6
0
114
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus