• 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. }

  • 相关阅读:
    (五)Selenium自动化测试实战—PO模式
    【Node】核心模块
    Java并发编程学习篇8_基于开源的配置中心的轻量动态线程池dynamic-tp实践与源码原理分析
    python教程:*的用法,你可能错过了......
    Go语言面试题
    Linux - 任务管理
    客快物流大数据项目(八十):用户标签开发
    【Kafka】Kafka基础架构及相关概念
    TIOBE 5 月榜单揭晓:哪些编程语言正在上升?
    【华为OD题库-008】座位调整-Java
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126052495