zoukankan      html  css  js  c++  java
  • Codeforces Round #304 (Div. 2) D

    D. Soldier and Number Game
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 test(s)
    input
    2
    3 1
    6 3
    
    output
    2
    

    5

    这题用到了一个公式,primefactors[a] = primefactors[a / primediviser[a]] + 1,primefactor[a]表示a因数中素数的个数。

    只要把a,b的primefactor[]算出来,减一下就行了。

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<algorithm>
    using namespace std;
    #define maxn 5000050
    int c[maxn],prime[maxn];
    void init()
    {
    	memset(c,0,sizeof(c));
    	int i,j,t;
    	t=1;
    	for(i=2;i<=maxn;i++){
    		if(c[i]==0){
    			for(j=2;j*i<=maxn;j++){
    				c[j*i]=c[j]+1;
    			}
    		}
    	}
    	for(i=3;i<=maxn;i++){
    		c[i]+=c[i-1];
    	}
    }
    
    int main()
    {
    	int a,b,i,j,T;
    	init();
    	scanf("%d",&T);
    	while(T--)
    	{
    		scanf("%d%d",&a,&b);
    		printf("%d
    ",c[a]+a-c[b]-b);
    	}
    	return 0;
    }


  • 相关阅读:
    高仿富途牛牛-组件化(三)-界面美化
    高仿富途牛牛-组件化(二)-磁力吸附
    高仿富途牛牛-组件化(一)-支持页签拖拽、增删、小工具
    Cef3 学习资料
    QCustomplot使用分享(八) 绘制图表-加载cvs文件
    Electron桌面应用:环境搭建
    Qt疑难问题-模态窗口父类被析构
    Qt线程实现分析-moveToThread vs 继承
    基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。
    asp.net中的ListBox控件添加双击事件
  • 原文地址:https://www.cnblogs.com/herumw/p/9464717.html
Copyright © 2011-2022 走看看