fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24. bool isPrime(int x){
  25. if(x<=1) return false;
  26. for(int i=2; i*i<=x; i++){
  27. if(x%i == 0) return false;
  28. }
  29. return true;
  30. }
  31.  
  32.  
  33. int floorPrime(int x){
  34.  
  35. while(!isPrime(x)){
  36. x--;
  37. }
  38.  
  39. return x;
  40.  
  41. }
  42.  
  43. void consistency(int x, int y) {
  44.  
  45. int a = floorPrime(x);
  46. int b = floorPrime(y);
  47.  
  48. cout << a-b << endl;
  49. cout << a << endl;
  50. }
  51.  
  52. void solve() {
  53.  
  54. int x, y;
  55. cin >> x >> y;
  56.  
  57. consistency(x, y) ;
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. int32_t main() {
  66. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  67.  
  68. int t = 1;
  69. cin >> t;
  70. while (t--) {
  71. solve();
  72. }
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 5316KB
stdin
2
20 10
10000000000 100000000
stdout
12
19
9899999978
9999999967