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

  • 相关阅读:
    新年学新语言Go之一
    【11】二进制编码:“手持两把锟斤拷,口中疾呼烫烫烫”?
    USB——硬件控制器分类(OHCI UHCI EHCI xHCI)))
    【操作指导 | 代码实现】挑战程序设计竞赛2:算法和数据结构
    springboot注解之@ConfigurationProperties注解
    laravel自定义日志保存文件加上日期
    JAVA 三元运算符
    力扣(LeetCode)容器装水问题
    解决Huggingface被墙下载模型的问题
    高效、优雅的对象copy之MapStruct入门到精通,实战踩坑版
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126052495