HDU 5750 bestcoder Round #84 dertouzos (Prime number screening) __hdu

Source: Internet
Author: User
Dertouzos Time limit:7000/3500 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 1518 accepted submission (s): 484

Problem Description A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself are not.

Peter has two positive integers n and D. He would like to know the number of integers below n whose maximum positive proper divisor are d. Input There are multiple Test cases. The "a" of input contains an integer T (1≤t≤106), indicating the number of test cases. For each test case:

The contains two integers n and D (2≤n,d≤109). Output for each test case, output an integer denoting the answer. Sample Input
9 2 3 Ten 4 5 a 6 a 7 a 8 9
1 2 1 0 0 0 0 0 4 Source bestcoder Round #84 recommend wange2014 | We have carefully selected several similar problems for you:5751 5746 5745 5744 5743: give you t N and D, and let you ask for the largest divisors in the number less than n (no including itself) is the number of D.

Because to make the maximum factor D, there must be x*d=m, and X must be a prime number, and x must be less than D's minimum decomposition, so find n before a few m set up. Because T range is very large, so you can first play the table to select the list of quality and then linear sweep it.


AC Code:

#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include < algorithm>
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace Std;

int isprime[100005]={0};
int prime[100005]={0};
int k=0;

int init ()
{
	int i,j;
	
	for (i=2;i<100000;i++)
	{
		if (isprime[i]==0)
		{for
			(j=2;i*j<100000;j++)
				isprime[i*j ]=1;
			prime[k]=i;
			k++
		}
	}
	return 0;
}

int main ()
{
	int t,i;
	int m,n;	
	scanf ("%d", &t);
	Init ();
	while (t--)
	{
		scanf ("%d%d", &m,&n);

		for (i=0;i<k;i++)
		{
			if (n*prime[i]>=m) break;
			if (N<prime[i]) break;
			if (n%prime[i]==0) break;
		if (N*prime[i]>=m | | n<prime[i]) i--;
		printf ("%d\n", i+1);
	}
	return 0;
}


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.