• B. Different Divisors- Codeforces Round #696 (Div. 2)


    Problem - 1474B - Codeforces

    B. Different Divisors

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Positive integer xx is called divisor of positive integer yy, if yy is divisible by xx without remainder. For example, 11 is a divisor of 77 and 33 is not divisor of 88.

    We gave you an integer dd and asked you to find the smallest positive integer aa, such that

    • aa has at least 44 divisors;
    • difference between any two divisors of aa is at least dd.

    Input

    The first line contains a single integer tt (1≤t≤30001≤t≤3000) — the number of test cases.

    The first line of each test case contains a single integer dd (1≤d≤100001≤d≤10000).

    Output

    For each test case print one integer aa — the answer for this test case.

    Example

    input

    Copy

    2
    1
    2
    

    output

    Copy

    6
    15
    

    Note

    In the first test case, integer 66 have following divisors: [1,2,3,6][1,2,3,6]. There are 44 of them and the difference between any two of them is at least 11. There is no smaller integer with at least 44 divisors.

    In the second test case, integer 1515 have following divisors: [1,3,5,15][1,3,5,15]. There are 44 of them and the difference between any two of them is at least 22.

    The answer 1212 is INVALID because divisors are [1,2,3,4,6,12][1,2,3,4,6,12]. And the difference between, for example, divisors 22 and 33 is less than d=2d=2.

    =========================================================================

    抓住4个因子的特殊性,第一个因子为1,一旦我们确定了中间两个因子,那么也就确定了这个数,因为这个数就等于中间两个因子之积,我们想让这个数最小,那么就让中间两个因子最小就够了。

    第二个因子必须大于d+1,第三个因子必须大于等于第二个因子+d

    如果第二个因子是一个合数,那么势必会有比第二个因子更小的因子出现在前面,所以两者必须是质数,欧拉筛筛出来一定数量的质数,再进行二分查找即可。

    1. # include
    2. # define mod 10
    3. using namespace std;
    4. typedef long long int ll;
    5. int prime[1000000+10];
    6. bool not_prime[1000000+10];
    7. int tot;
    8. void init()
    9. {
    10. for(int i=2;i<=1000000;i++)
    11. {
    12. if(!not_prime[i])
    13. {
    14. tot++;
    15. prime[tot]=i;
    16. }
    17. for(int j=1;j<=tot&&i*prime[j]<=1000000;j++)
    18. {
    19. not_prime[i*prime[j]]=1;
    20. if(i%prime[j]==0)
    21. {
    22. break;
    23. }
    24. }
    25. }
    26. }
    27. int main ()
    28. {
    29. init();
    30. int t;
    31. cin>>t;
    32. while(t--)
    33. {
    34. int d;
    35. cin>>d;
    36. ll x1=d+1;
    37. int pos=lower_bound(prime+1,prime+1+tot,x1)-prime;
    38. x1=prime[pos];
    39. ll x2=x1+d;
    40. pos=lower_bound(prime+1,prime+1+tot,x2)-prime;
    41. x2=prime[pos];
    42. cout<
    43. }
    44. return 0;
    45. }

  • 相关阅读:
    Python 基于 OpenCV 视觉图像处理实战 之 背景知识
    详解--Hash(中文也称散列、哈希)
    前端经典面试题 | v-if/v-show的原理及区别
    java+ssh+mysql学生考勤管理系统
    UI设计需要学会哪些软件?优漫动游
    c盘分小了如何扩大c盘,重新分区扩大c盘
    破天荒呀!小杜微信有名额了
    css的属性选择器的妙用,来用它实现一个轻量的tips组件吧
    微信小程序详细教程-建议收藏
    使用 ES|QL 优化可观察性:简化 Kubernetes 和 OTel 的 SRE 操作和问题解决
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126052495