zoukankan      html  css  js  c++  java
  • Codeforces Round #641 (Div. 2) A. Orac and Factors(数学)

    Orac is studying number theory, and he is interested in the properties of divisors.

    For two positive integers aa and bb , aa is a divisor of bb if and only if there exists an integer cc , such that ac=ba⋅c=b .

    For n2n≥2 , we will denote as f(n)f(n) the smallest positive divisor of nn , except 11 .

    For example, f(7)=7,f(10)=2,f(35)=5f(7)=7,f(10)=2,f(35)=5 .

    For the fixed integer nn , Orac decided to add f(n)f(n) to nn .

    For example, if he had an integer n=5n=5 , the new value of nn will be equal to 1010 . And if he had an integer n=6n=6 , nn will be changed to 88 .

    Orac loved it so much, so he decided to repeat this operation several times.

    Now, for two positive integers nn and kk , Orac asked you to add f(n)f(n) to nn exactly kk times (note that nn will change after each operation, so f(n)f(n) may change too) and tell him the final value of nn .

    For example, if Orac gives you n=5n=5 and k=2k=2 , at first you should add f(5)=5f(5)=5 to n=5n=5 , so your new value of nn will be equal to n=10n=10 , after that, you should add f(10)=2f(10)=2 to 1010 , so your new (and the final!) value of nn will be equal to 1212 .

    Orac may ask you these queries many times.

    Input

    The first line of the input is a single integer t (1t100)t (1≤t≤100) : the number of times that Orac will ask you.

    Each of the next tt lines contains two positive integers n,k (2n106,1k109)n,k (2≤n≤106,1≤k≤109) , corresponding to a query by Orac.

    It is guaranteed that the total sum of nn is at most 106106 .

    Output

    Print tt lines, the ii -th of them should contain the final value of nn in the ii -th query by Orac.

    Example
    Input
    Copy
    3
    5 1
    8 2
    3 4
    
    Output
    Copy
    10
    12
    12
    首先注意到n为偶数的话其最小因子一定是2,直接输出n+2*k即可。
    然后预处理出每个数的最小因子a[i](类似筛法),n是奇数的话直接输出n+a[i]+2*(n-1)即可。因为奇数的最小因子还是奇数,奇数加奇数就成了偶数。
    #include <bits/stdc++.h>
    using namespace std;
    int a[2000005]={0};
    int main()
    {
        int t;
        cin>>t;
        int i;
        for(i=2;i<=2000000;i++)
        {
            if(!a[i])
            {
                int j;
                for(j=i;j<=2000000;j+=i)
                {
                    if(!a[j])a[j]=i;
                }
            }
        }
        while(t--)
        {
            int n,k;
            cin>>n>>k;
            if(n&1) cout<<n+a[n]+(k-1)*2<<endl;
            else cout<<n+2*k<<endl;
        }
    }
  • 相关阅读:
    转:[windows]DOS批处理添加任务计划
    转:winform_webApiSelfHost及 OWIN WebAPI Service
    Ubuntu上将终端安装到右键上
    Ubuntu上安装VMware tools
    OpenStack中的rabbitmq的配置方法
    centos上的grub文件修改
    centos7上安装0penStack
    怎样使用yum安装OpenStack
    epel扩展库的安装
    centos7上修改主机名
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12880625.html
Copyright © 2011-2022 走看看