Codeforces 1062B Math(质因数分解)
题意:
给一个数n,可以将它乘任意数,或者开方,问你能得到的最小数是多少,并给出最小操作次数
思路:
能将这个数变小的操作只能是开方,所以构成的最小数一定是
$n = p_1*p_2*p_3*\dots *p_m$ 其中$p_i$为不同的质数
由唯一分解定理,我们需要把初始的n通过乘法变成可以(多次)开方成上数的形式
不引入多余的质因子,就是最小的数
一次乘法(如果需要乘的话)+数次开方就是最小操作次数
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int main() {
int n;
scanf("%d", &n);
if(n==)return printf("1 0"),;
int mx = -;
int mn = maxn;
int ans = ;
int p = ;
for(int i = ; n > ; i++){
if(n%i==){
int c = ;
ans*=i;
while(n%i==){
n/=i;
c++;
}
mn = min(mn, c);
mx = max(mx, c);
}
}
int v = ;
while(v < mx){
v*=;
p++;
}
if(v!=mn)p++;
printf("%d %d",ans,p); return ;
}
Codeforces 1062B Math(质因数分解)的更多相关文章
- CodeForces - 1228C(质因数分解+贡献法)
题意 https://vjudge.net/problem/CodeForces-1228C 首先先介绍一些涉及到的定义: 定义prime(x)表示x的质因子集合.举例来说,prime(140)={2 ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 素数打表+质因数分解
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- POJ1365 - Prime Land(质因数分解)
题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...
- 【(阶乘的质因数分解)算组合数】【TOJ4111】【Binomial efficient】
n<=10^6 m<=10^6 p=2^32 用unsigned int 可以避免取模 我写的SB超时 阶乘分解代码 #include <cstdio> #include &l ...
- CF 757E Bash Plays with Functions——积性函数+dp+质因数分解
题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...
- CF 757 E Bash Plays with Functions —— 积性函数与质因数分解
题目:http://codeforces.com/contest/757/problem/E 首先,f0(n)=2m,其中 m 是 n 的质因数的种类数: 而且 因为这个函数和1卷积,所以是一个积性函 ...
- Project Euler 29 Distinct powers( 大整数质因数分解做法 + 普通做法 )
题意: 考虑所有满足2 ≤ a ≤ 5和2 ≤ b ≤ 5的整数组合生成的幂ab: 22=4, 23=8, 24=16, 25=3232=9, 33=27, 34=81, 35=24342=16, 4 ...
- 求n!质因数分解之后素数a的个数
n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...
- AC日记——质因数分解 1.5 43
43:质因数分解 总时间限制: 1000ms 内存限制: 65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...
随机推荐
- ASP.NET Core Web程序托管到Windows 服务
前言 在 .NET Core 3.1和WorkerServices构建Windows服务 我们也看到了,如何将workerservices构建成服务,那么本篇文章我们再来看看如何将web应用程序托管到 ...
- PS/2的相关知识
PS/2接口 很多微机上采用PS/2口来连接鼠标和键盘.PS/2接口与传统的键盘接口除了在接口外型.引脚有不同外,在数据传送格式上是相同的.现在很多主板用PS/2接口插座连接键盘,传统接口的键盘可以通 ...
- Arrays.sort() VS Arrays.parallelSort()
英文原文地址:Arrays.sort vs Arrays.parallelSort 作者:baeldung 翻译:高行行 1. 概述 我们都使用过 Arrays.sort() 对对象或原始数据类型数组 ...
- 一些常用查询SQL语句以及显示格式
1.查询当前年.月.周相关时间 1.1.查询当前年份 SELECT TO_CHAR(SYSDATE,'YYYY') AS YEAR FROM DUAL--查询当前年份 SELECT TO_CHAR(S ...
- 矩形内的递推dp
链接:https://www.nowcoder.com/acm/contest/130/B来源:牛客网 黑妹和黑弟又聚在一起玩游戏了,这次他们选择在一个n*m的棋盘上玩游戏,棋盘上的每个方格都有一个非 ...
- JSON解析值富文本
解析前端传递的JSON数据中可能如下 { "result": "<input value="Test" type="button&qu ...
- 【红外DDE算法】聊聊红外图像增强算法的历史进程(第一回)
宽动态红外图像增强算法综述回顾过去带你回顾宽动态红外图像增强算法的历史进程,历来学者的一步步革命(新的算法框架提出),一步步改革(改进优化),从简单粗暴到细致全面.正所谓是:改革没有完成时,只有进行时 ...
- cocos2dx,Layer锚点与scale缩放
最近写代码需要用到缩放,而且是Layer的,但是发现怎么设置位置都是错误,于是决定研究下. 首先,基础代码,代码上不错特殊处理,没有锚点设置和缩放 class TestLayer : public L ...
- Python 练习实例100 | 菜鸟教程
http://www.runoob.com/python/python-exercise-example100.html
- mong 按 geometry 搜索 地理位置信息
看 地理位置索引的使用 $near $geometry