HDU 5750 Dertouzos Simple Math

Source: Internet
Author: User

Sentiment: This is another zimpha huge problem, then 04 successful FST (that is, the problem)

In fact, too young, trying to increase posture,

Analysis: Direct enumeration of these numbers is not good enumeration, another angle, enumeration x*d, that is, the second multiplier of D is how much

Obviously X<=min (d, (n-1)/d), X is also prime, and finally found that x must be less than the minimum factor of D

The prime number within 10w is then preprocessed, and then each time K=min (d, (n-1)/d) is first obtained, and then the D minimum factor is less than K

The key to the problem is to find the minimum factor of D, I am violent looking (and then hit all the big primes on the T)

In fact, when D is a large prime number, K is small, direct enumeration of prime numbers, if greater than K has not, you do not have to find (anyway to the smallest)

After the game, this one limit is over.

Spit Groove: Still Young

#include <stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<vector>#include<math.h>#include<stack>#include<map>#defineX First#defineY Secondusing namespaceStd;typedefLong LongLL;Const intN = 1e5+5;Const intINF =0x3f3f3f3f; typedef pair<int,int>PII;BOOLVis[n];intPrime[n>>1],tot;voidGetprime () { for(intI=2; i*i<=n-5;++i) {    if(Vis[i])Continue;  for(intj=i*i;j<=n-5; j+=i) vis[j]=true; }   for(intI=2; i<=n-5;++i)if(!vis[i]) prime[++tot]=i;}intMain () {getprime (); intT; scanf ("%d",&T);  while(t--){   intn,d; scanf ("%d%d",&n,&d); intTmp=min (d, (n1)/d); intflag=-1;  for(intI=1; i<=tot&&prime[i]<=tmp&&1ll*prime[i]*prime[i]<=d;++i) {      if(D%prime[i])Continue; Else{Flag=prime[i]; Break;} }   if(flag==-1) flag=D; TMP=min (Tmp,flag); intK=lower_bound (prime+1, prime+1+TOT,TMP)-Prime; if(k==tot+1|| PRIME[K]&GT;TMP)--K; printf ("%d\n", K); }  return 0;}
View Code

HDU 5750 Dertouzos Simple Math

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.