2015 Multi-University Training Contest 3 1002 RGCDQ

简介: RGCDQ  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5317   Mean:  定义函数f(x)表示:x的不同素因子个数。

RGCDQ 

Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5317


 

Mean: 

定义函数f(x)表示:x的不同素因子个数。

如:f(2) = 1, f(6) = 2;

给定L和R(L<=i<j<=R),求区间内任意不相等的两个数f(x)的最大公约数的最大值。

analyse:

因为2*3*5*7*11*13*17 >1e6,所以f(x)的值最大为7;

我们先打表求出每个数的f(x)值;

f[i][j]表示2~i中质因数个数为j的个数。

然后再利用前缀和f[r][i] - f[l-1][i],求出区间[l, r]的值。

Time complexity: O(NlogN)

 

Source code: 

/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-07-28-19.01
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define  LL long long
#define  ULL unsigned long long
using namespace std;

int T , a , b;
int f [ 1000009 ][ 10 ];
const int NN = 1000005;
int p [NN ];
bool v [NN ];
void cntPrimeNum()
{
      for( int i = 2; i < NN; ++ i )
      {
            if( ! v [ i ] )
                  for( int j = i; j < NN; j += i )
                  {
                        v [ j ] = true;
                        ++p [ j ];
                  }
      }
}

int main()
{
      cntPrimeNum();
      for( int i = 1; i < NN; ++ i )
            for( int j = 7; j > 0; -- j )
                  if( p [ i ] == j ) f [ i ][ j ] = 1;
      for( int i = 1; i <= 1000000; ++ i )
            for( int j = 1; j <= 7; ++ j )
                  f [ i ][ j ] += f [ i - 1 ][ j ];
      scanf( "%d" , & T );
      while( T -- )
      {
            int ans = 1;
            scanf( "%d %d" , & a , &b );
            for( int i = 7; i > 0; -- i )
            {
                  if( f [b ][ i ] - f [ a - 1 ][ i ] > 1 )
                  {
                        ans = i;
                        break;
                  }
            }
            printf( "%d \n " , ans );
      }
      return 0;
}

 

目录
相关文章
|
Java
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
130 0
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
108 0
|
Java
HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple
HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple
97 0
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
102 0
|
Java
2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 127    Accepted Submission(s): 20 Pro...
1415 0
|
Java
2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1060    Accepted Submission(...
1208 0
2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1539    Accepted Submission(s...
1335 0
|
Java 人工智能 BI
2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 652    Accepted Submission(s): 267...
1190 0