日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Primality Test 素数,打表

發布時間:2025/3/19 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Primality Test 素数,打表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  • 題意 :f(x)f(x)f(x)是嚴格大于x的最小質數,g(x)=[f(x)+f(f(x))]/2g(x)=[f(x)+f(f(x))]/2g(x)=[f(x)+f(f(x))]/2的向下取整,判斷g(x)g(x)g(x)是否是質數
  • 思路 :f(f(x))即f(x)相鄰的下一個質數,g(x)在相鄰兩個質數之間,所以g(x)一定是合數,除了x=1的情況下,f(1)=2,f(2)=3,即除了2和3之間以外
  • 語法 :long long 9e18多,int 2e9多
#include <iostream> #define endl '\n'using namespace std;typedef long long ll;int main() {int T;cin >> T;while (T -- ){ll x;cin >> x;if (x == 1) cout << "YES" << endl;else cout << "NO" << endl;}return 0; } //打表 #include<bits/stdc++.h> using namespace std; typedef long long LL;const int maxn = 1e9+10;int is_prime(LL x){for(LL i = 2; i*i <= x; i++){if(x%i==0){return 0;}}return 1; }int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int T; cin>>T;while(T--){LL x=T; // cin>>x;LL i;for(i = x+1; ; i++){if(is_prime(i)){break;}}LL j;for(j = i+1; ; j++){if(is_prime(j)){break;}}LL k = (i+j)/2;if(is_prime(k))cout<<"YES\n";else cout<<"NO\n";}return 0; }

總結

以上是生活随笔為你收集整理的Primality Test 素数,打表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。