码迷,mamicode.com
首页 > 其他好文 > 详细

Meow Factor 【暴力】

时间:2020-05-13 00:31:44      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:ble   stay   higher   input   ons   ash   bit   sqrt   VID   

题目链接

Meow Factor

题目

Among many of the Catland club kittens it is important to keep a paw on the pulse of the latest fashions and trends in order to stay hip. When a new number is discovered in Catland, its coolness is primarily determined by its meow factor. For a positive integer n, its meow factor is the largest integer m such that n is evenly divisible by m nine times (once for each life of a cat). We say that n is divisible by m nine times if, starting with n, you can divide it by m without a remainder, take the result of the division and again divide it by m without a remainder, and so on, dividing by m nine times in total.
While some cats are naturally chic and have an innate ability to see the meow factor of numbers, others who struggle to stay in vogue can not even tell the difference between 3584 and 4711 (the former clearly having a higher meow factor). Can you help those poor unfortunate cats lacking a sense of style, by writing a program to determine the meow factor of a number?

Input
The input contains a single integer \(n (1≤n≤26^3?1)\).

Output
Output the meow factor of n.

大概意思就是 给你一个数n,你要求出一个数m,m是能够让 \((n/m)/m...\)这样除以m 九次并且,每次都没有余数 的最大数。

思路

  • 一开始是想把n合数分解,然后找到最大的m,但是tle了
  • 然后搜题解发现根本不需要合数分解为质数!只要枚举就好了!
  • 注意,不是找指数大于9最大的,而是所有指数是9的倍数的,每个都要相乘,假如\(3^{12}*4^{20}\),则需要\(3*4*4\)

代码

  • 注释掉的大段代码是之前tle的合数分解
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
const int MAXN=100000;
/*int prime[MAXN+2];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
//		printf("i:%d\n",i);
		if(!prime[i]) prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}
ll factor[100][2];
int fatCnt;*/
/*void getFactors( ll x)
{
	fatCnt=0;
	ll tmp=x;
	for(int i=1;prime[i]<=tmp/prime[i];i++)
	{
		if(tmp%prime[i]==0)
		{
			factor[fatCnt][0]=prime[i];
			while(tmp%prime[i]==0)
			{
				factor[fatCnt][1]++;
				tmp/=prime[i];
			}
			fatCnt++;
		}
	}
	if(tmp!=1)
	{
		factor[fatCnt][0]=tmp;
		factor[fatCnt++][1]=1;
	}
}*/
map<ll,ll> getFactors(ll x)
{
	map<ll,ll> m;
	for(ll i=2;i<=min((ll)sqrt(x),1ll*MAXN);i++)
	{
		while(x%i==0)
		{
			m[i]++;
			x/=i;
		}
	}
	if(x>1)
		m[x]++;
	return m;
}
int main()
{
	scanf("%lld",&n);
	map<ll,ll> m = getFactors(n);
	ll mx=1;
	ll t;
	for(auto & i: m)
	{
		while(i.second >=9)
		{
			i.second-=9;
			mx *= i.first;
		}
	 } 
	printf("%lld\n",mx);
	return 0;
 } 

Meow Factor 【暴力】

标签:ble   stay   higher   input   ons   ash   bit   sqrt   VID   

原文地址:https://www.cnblogs.com/xuwanwei/p/12879736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!