URAL 1748. The Most Complex Number 反素数

题目来源:URAL 1748. The Most Complex Number

题意:求一个小于等于n的因子最多的数

思路:搜索+剪枝

#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned __int64 LL;
LL prime[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
LL num, sum, n;

void dfs(int p, int q, LL x, LL y)
{
	if(p >= 16)
		return;
	if(x > n)
		return;
	if(y > sum)
	{
		num = x;
		sum = y;
	}
	if(y == sum && num > x)
		num = x;
	for(int i = 1; i <= q; i++)
	{
		double tmp = (double)x;
		if(tmp*prime[p] > n)
			break;
		dfs(p+1, i, x *= prime[p], y*(1+i));
	}
}
int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%I64u", &n);
		sum = 0;
		dfs(0, 60, 1, 1);
		printf("%I64u %I64u\n", num, sum);
	}
	return 0;
}
时间: 2024-09-29 09:14:36

URAL 1748. The Most Complex Number 反素数的相关文章

URAL 1748. The Most Complex Number(反素数)

题目链接 题意 :给你一个n,让你找出小于等于n的数中因子个数最多的那个数,并且输出因子个数,如果有多个答案,输出数最小的那个 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. (2)我们可以知道,计算约数的个数和质因数分解有着很大的联系: 若Q的质因数分解为:Q=p1^k1*p2^k2*…*pm^km(p1…pm为素数,k1…km≥1),则Q有(k1+1)(k2+1)…(km+1)个约数.但是质因数分解的时间复杂度很高,所以也会超时. (3)通过以上的公式,我们可以“突发奇

poj 2886 Who Gets the Most Candies?(线段树+约瑟夫环+反素数)

Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9934   Accepted: 3050 Case Time Limit: 2000MS Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise o

zoj2562--More Divisors(反素数模板)

More Divisors Time Limit: 2 Seconds      Memory Limit: 65536 KB Everybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often

POJ2886 Who Gets the Most Candies? 【线段树】+【单点更新】+【模拟】+【反素数】

Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9416   Accepted: 2868 Case Time Limit: 2000MS Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise o

Who Gets the Most Candies?(线段树 + 反素数 )

Who Gets the Most Candies? Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise order. Each of th

[SDOI2005]反素数ant

题目描述 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数1,2,4,6等都是反质数. 现在给定一个数N,你能求出不超过N的最大的反质数么? 输入输出格式 输入格式: 一个数N(1<=N<=2,000,000,000). 输出格式: 不超过N的最大的反质数. 输入输出样例 输入样例#1: 1000 输出样例#1: 840 根据整数的唯一分解定理,每个反素数都可以分解为

POJ - 2886 Who Gets the Most Candies? (反素数+线段树)

Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from the K-th child, who tells all the oth

(中等) POJ 2886 Who Gets the Most Candies? , 反素数+线段树。

Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from the K-th child, who tells all the oth

poj 2886 线段树的更新+反素数

Who Gets the Most Candies? Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description N children are sitting in a circle to play a game. The children are numbered from