zoukankan      html  css  js  c++  java
  • Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数

    D. Soldier and Number Game

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/546/problem/D

    Description

    Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed.

    To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a ≥ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k.

    What is the maximum possible score of the second soldier?

    Input

    First line of input consists of single integer t (1 ≤ t ≤ 1 000 000) denoting number of games soldiers play.

    Then follow t lines, each contains pair of integers a and b (1 ≤ b ≤ a ≤ 5 000 000) defining the value of n for a game.

    Output

    For each game output a maximum score that the second soldier can get.

    Sample Input

    2
    3 1
    6 3

    Sample Output

    2
    5

    HINT

    题意

    给你 a,b,求a到b的数的质因数个数和

    题解:

    线性筛法,类似与dp的一种筛法

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 5000001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    
    int cnt[maxn];
    long long sum[maxn];
    
    void init()
    {
        for(int i=2;i<maxn;i++)
            if(!cnt[i])
                for(int j=i,c=1;j<maxn;j+=i,c++)
                {
                    int t=c;
                    while(1)
                    {
                        cnt[j]++;
                        if (t%i) break;
                        t/=i;
                    }
                }
        for(int i=2;i<=maxn;i++) 
            sum[i]=sum[i-1]+cnt[i];
    }
    int main()
    {
        init();
        int t,a,b;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %d",&a,&b);
            printf("%d
    ",sum[a]-sum[b]);
        }
    }
  • 相关阅读:
    使用代码为textview设置drawableLeft
    Android Studio下添加assets目录
    lib32asound2 : Depends: libc6-i386 (>= 2.7) but it is not going to be installed
    android addJavascriptInterface 不能生效 解决办法
    [Android] 判断手机上是否安装了某个程序
    Github如何回退/回滚到某个版本
    Android导入第三方静态库.a编译成动态库.so
    (总结)Ubuntu apt-get apt-cache命令 使用
    C++11多线程std::thread的简单使用
    Android防止进程被第三方软件杀死
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4523625.html
Copyright © 2011-2022 走看看