HDU more than 5,317 schools in the third field

Source: Internet
Author: User

Start test instructions read the wrong shit WA a long time carefully see really water problem one;

It is easy to draw the F () value of each number according to the prime numbers, so you can see that the value of 1 to 1000000 F () is 7 and (2*3*5*7*11*13*17) tells you that the interval only needs to find these 7 numbers in this interval. How many times are there a two-dimensional array of leap "I" "J" (J is less than or equal to 7) indicates the number of J occurrences before I so it's easy to find the value of the interval J. In the record array, you can ask for gcd. Here I am directly listed in all cases!!!


#include <stdio.h> #include <string.h> #include <iostream>using namespaceStd;#define LL (x) (x<<1) #define RR (x) ((x<<1) | |intCont[1000100]={0},Mark[1000010]={0},Leap[1000010][8]={0}; int Max (int A ,int B ) {  return A>B?A:B;} int Main () {  int I,J;Memset(Mark,0 ,sizeof( Mark));Memset(Cont,0 ,sizeof( Cont));  for (I=2;I<=1000000;I + +) {  if( Mark[I ])  continue; Cont[I]=1;  for (J=I+I;J<=1000000;J+=I) {Cont[J]++;Mark[J]=1; }} for ( I=2;I<=1000000;I + +) {  for( J=1;J<=7;J++) {Leap[I][J]=Leap[I-1][J]; }Leap[I][Cont[I]]++; }  int T,L,R;scanf("%d",&T);  while (T--) {scanf("%d%d",&L,&R); int Record[8];Memset(Record,0 ,sizeof( Record));  for (I=1;I<=7;I++) {Record[I]=Leap[R][I]-Leap[L-1][I]; }  int Ans=1;  for (I=1;I<=7;I + +) {  if( Record[I]==0 )  continue; if (Record[I]>1)Ans=Max(Ans,I);  for (J=I+1;J<=7;J + +) {  if( Record[J]==0 )  continue; else if (I==2&&J==4 ) {  if( Ans<2)Ans=2; }  Else if( I==2&&J==6 ) {  if( Ans<2)Ans=2; }  Else if( I==4&&J==6 ) {  if( Ans<2)Ans=2; }  Else if( I==3&&J==6 ) {  if( Ans<3)Ans=3; } } }Printf("%d\n",Ans); }  return 0;} 

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU more than 5,317 schools in the third field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.