标签:acm
3 6 8 10
5 1 7 1 11 1
#include <iostream> #include <cmath> using namespace std; bool isPrime(int lhs) { for (int i = 2; i <= sqrt(lhs); i++) { if (!(lhs % i)) return false; } return true; } int main() { int n, m,m1,m11,m2,m22,t1,t2,i; bool flag; cin >> n; while (n--) { cin >> m; m1 = m2 = m; m11 = m22 = 0; t1 = t2 = 0; if (1==m) { cout << 2 << " " << 1 << endl; } else { while (m1) { if (isPrime(m1)) { m11 = m1; t1 = m - m11; break; } --m1; } while (m2) { if (isPrime(m2)) { m22 = m2; t2 = m22 - m; break; } ++m2; } if (t1 > t2) cout << m22 << " " << t2 << endl; else cout << m11 << " " << t1 << endl; } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:acm
原文地址:http://blog.csdn.net/u011694809/article/details/48107351