Hdu_5750_dertouzos (linear sieve)

Source: Internet
Author: User

Topic Connection: Hdu_5750_dertouzos

Test instructions

Give you a N, a D, ask you how many of the numbers in the small number of n is the largest factor of D, such as 6 has a factor 1 2 3 the largest is 3

Exercises

At that time, the game did not consider the optimization of the constant, after the first Test, and then FST, lying trough ...

Careful observation of the problem can be found we only need to find a number s,s*d is smaller than N, and S is not greater than the smallest qualitative factor of d, in order to make s*d the largest factor of this number is D. Then we use the linear sieve first to sift out the prime of 2W, in fact, should be screened to 33333, but I tested the data 2W can also pass, and then just sweep the line

1#include <cstdio>2 #defineF (I,A,B) for (int i=a;i<=b;++i)3 4 intprimes[30000],tot=0, n=20000;5 BOOLvis[20001];6 voidEuler () {7F (I,2, N) {8         if(!vis[i]) primes[++tot]=i;9F (J,1, tot) {Ten             if(i*primes[j]>n) Break; Onevis[i*primes[j]]=1; A             if(i%primes[j]==0) Break; -         } -     } the } - intMain () { - Euler (); -     intt,n,d; +scanf"%d",&t); -      while(t--) +     { Ascanf"%d%d",&n,&d); at         intmi=-1, tp= (n1)/d,ans=0; -          for(intI=1; i<tot;i++) -         { -             if(PRIMES[I]&GT;TP) Break; -ans++; -             if(d%primes[i]==0) Break;//If D is a multiple of the current prime number, then the next prime number is definitely larger than the prime number, so exit directly in         } -printf"%d\n", ans); to     } +     return 0; -}
View Code

Hdu_5750_dertouzos (linear sieve)

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.