I need a function that returns the smallest prime number p smaller than 100,000 such that (p + n) is also prime, where n is a scalar integer and is the sole input argument to the function
1 回表示 (過去 30 日間)
古いコメントを表示
Write a function called prime_pairs that returns the smallest prime number p smaller than 100,000 such that (p + n) is also prime, where n is a scalar integer and is the sole input argument to the function. If no such number exists, then the function returns -1. You may use the built-in functions, primes and isprime.
3 件のコメント
採用された回答
その他の回答 (1 件)
charu sharma
2015 年 8 月 27 日
For simple code refer this and ask if you have any query: http://farzicoders.blogspot.in/2015/08/write-function-called-primepairs-that.html
1 件のコメント
Stephen23
2015 年 8 月 27 日
"simple code" with:
- poorly named variables: for i=1:l
- superfluous intermediate variables: flag
- superfluous loops when code vectorization would be neater.
- superfluous return statements.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!