fork download
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int T;
  9. scanf("%d",&T);
  10. int prime[10000]={0};
  11. prime[0] = 1;
  12. prime[1] = 1;
  13. for(int i = 2 ;i<10000;i++)
  14. {
  15. if(prime[i] == 0)
  16. {
  17. for(int j = 2 ;i*j<10000;j++)
  18. prime[i*j] = 1;
  19. }
  20. }
  21. while(T--)
  22. {
  23. int a,b;
  24. scanf("%d%d",&a,&b);
  25. for(int i = 1;i<10000;i++)
  26. {
  27. if(prime[i+a+b] == 0)
  28. {
  29. printf("%d\n",i);
  30. break;
  31. }
  32.  
  33. }
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 3416KB
stdin
2
1 3
1000 1000
stdout
1
3