fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. // tle eleminators video;
  4. // min number generated by 4 divisiors, more divisors bigger the number so, we need exactly 4 divisiors
  5.  
  6. // there is this formula of combimetrics which states that the divios if number n is combination of
  7. // prime numebrs to its powers somthing like that
  8. //by that logic
  9. // divisior logic theorem
  10. //(alpha +1)*(beta +1)*(gamma+1)*(delta+1) == 4
  11.  
  12. // case 1 : 4 * 1 * 1 * 1 e.g. 1 3 9 27
  13. // case 2: 2 * 2 * 1 * 1 e.g. 1 3 7 21
  14. // by that logic to have
  15.  
  16. long long next_prime(long long n){
  17.  
  18. for(long long i = n;;i++){// dont have second term because it will eventually break to some primr number// preetiliy explained in tle video
  19. bool isprime = true;
  20. for(long long j =2 ; j*j <= i; j++){// j= 2 bcz 1 is not prime number
  21. if(i%j == 0){
  22. isprime =false;
  23. break;
  24. }
  25. }
  26.  
  27. if(isprime){
  28. return i;
  29. }
  30.  
  31.  
  32. }
  33.  
  34. }
  35.  
  36.  
  37. int main() {
  38. int t;
  39. cin>>t;
  40. while(t--){
  41. long long d;
  42. cin>>d;
  43. // case 1 : 1 p p^2 p^3
  44.  
  45. //case 2;
  46. // 1 p q pq
  47. //p-1 >=d q-p >=d
  48. long long p = next_prime(d+1);//O(1000)
  49. long long q = next_prime(d+p);//O(1000)
  50.  
  51. long long a = min(p*p*p , p*q);
  52.  
  53. cout<<a<<endl;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5284KB
stdin
2
1
2
stdout
6
15