DSA06014 - Tổng cặp số nguyên tố
unknown
plain_text
a year ago
1.0 kB
19
Indexable
#include<bits/stdc++.h> using namespace std; long long prime[10000001]; vector<int> snt; void sangEratosthenes(){ //Gan tat ca mang ban dau deu la so nguyen to; for(int i = 0; i < 1000000; i++){ prime[i] = 1; } //So 0 va so 1 luôn khong phai la so nguyen to nen gan cho chung bang 0; prime[0] = prime[1] = 0; //Duyet tu i den sqrt(1000000) vi cac so mu 2 se luon co it nhat 3 uoc for(int i=2; i < sqrt(1000000); i++){ if(prime[i]){ snt.push_back(i); for(int j = i*i; j <= 1000000; j+=i){ prime[j] = 0; } } } // for(int i = 0; i < snt.size(); i++){ // cout<<snt[i]<<" "; // } } int main(){ sangEratosthenes(); int t; cin>>t; while(t--){ int n; cin>>n; bool check = false; for(int i = 0; i < snt.size(); i++){ if(!check){ for(int j = 0; j < snt.size(); j++){ if(snt[i] + snt[j] == n){ check = true; cout<<snt[i]<<" "<<snt[j]<<endl; } } } } if(!check){ cout<<"-1"<<endl; } } return 0; }
Editor is loading...
Leave a Comment