/*** | |
Md. Nazmul Hasan | |
Shahjalal University of Science & Technology,Sylhet. | |
hasan08sust@gmail.com | |
***/ | |
#include<iostream> | |
#include<cstdio> | |
#include<stack> | |
#include<queue> | |
#include<map> | |
#include<vector> | |
#include<algorithm> | |
#include<cstring> | |
#include<sstream> | |
#include<cmath> | |
#include <iomanip> | |
using namespace std ; | |
typedef long long ll ; | |
typedef int in ; | |
typedef unsigned long long ull ; | |
const double pi = 2*acos(0) ; | |
#define maxi 1000001 | |
#define pf printf | |
#define sc scanf | |
#define pb push_back | |
#define MEM(x,y) (memset((x),(y),sizeof(x))) | |
#define MIN(x,y) ((x) < (y) ? (x) : (y)) | |
#define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ; | |
#define new_line pf("\n") | |
#define clear_data(array) memset(array,0,sizeof(array)) | |
#define highest_int 2147483647 | |
bool isPrime[maxi]; | |
vector<int> data; | |
int x,n; | |
void sieve(){ | |
memset(isPrime,true , sizeof(isPrime)); | |
isPrime[0] = isPrime[1] = false; | |
for(int i=4 ; i<=maxi ; i+=2){ | |
isPrime[i] = false; | |
} | |
for(int i=3 ; i*i<maxi ; i+=2){ | |
if(isPrime[i]){ | |
for(int j=i*i ; j<maxi ; j+=i+i) | |
isPrime[j] = false; | |
} | |
} | |
data.pb(2); | |
for(int i=3 ; i<maxi ; i+=2) | |
if(isPrime[i]) | |
data.pb(i); | |
} | |
bool check(){ | |
if(n%2 || n==4){ | |
x =2 ; | |
return isPrime[n-x]; | |
} | |
for(int i=1 ; i<data.size() && data[i]<=n/2 ; i++){ | |
if(isPrime[n-data[i]]){ | |
x = data[i]; | |
return true; | |
} | |
} | |
return false; | |
} | |
int main() | |
{ | |
sieve(); | |
while(sc("%d",&n) && n){ | |
pf("%d:\n",n); | |
if(check()){ | |
pf("%d+%d\n",x,n-x); | |
}else{ | |
pf("NO WAY!\n"); | |
} | |
} | |
return 0; | |
} |
03 November 2017
UVA 10948 The primary problem
Subscribe to:
Post Comments (Atom)
-
/*** Md. Nazmul Hasan Shahjalal University of Science & Technology,Sylhet. hasan08sust@gmail.com ***/ #include<iostream> #i...
-
n = 1 while n: str = input () # print('Case no# %d :'%n) if str == ' * ' : break if str == ' Hajj ...
-
/*** Md. Namzul Hasan Shahjalal University of Science & technology,sylhet. hasan08sust@gmail.com ***/ #include<bits/stdc++.h...
No comments:
Post a Comment