Codeforces Round #520 (Div. 2)B(贪心,数学)
#include<bits/stdc++.h>
using namespace std;
int mi[100007];
int main(){
int cnt=0;
int flag=0;
int ans=1;
int n,k=0;
scanf("%d",&n);
for(int i=2;i*i<=n;i++){
if(n%i==0){
flag=1;
break;
}
}
if(flag==0)//如果不用操作直接输出即可
printf("%d %d",n,k);
else{
for(int i=2;i*i<=n;i++){
if(n%i==0){
ans*=i;//有小到大寻找可分解的因数
cnt++;
while(n%i==0){
n/=i;
mi[cnt]++;//记录能被分解几次
}
}
}
if(n>1){//剩余大于根号n的仍未分解
cnt++;
mi[cnt]++;
ans*=n;//记录在案,ans是由无法继续分解的数相乘组成的
}
int mx=0;
for(int i=1;i<=cnt;i++)
mx=max(mx,mi[i]);//找到能被操作次数最多的
k=(int)ceil(log(mx*1.0)/log(2.0));//开方次数
int x=pow(2,k);//实际操作的最大值
for(int i=1;i<=cnt;i++)
if(mi[i]!=x){//不理想的情况(不用乘直接开方)是需要乘一次的,贪心地乘一次直接把所有数组里的值由哪些数得来的乘到数组值变为x
k++;//多出一次乘法操作
break;
}
printf("%d %d",ans,k);
}
return 0;
}
Codeforces Round #520 (Div. 2)B(贪心,数学)的更多相关文章
- Codeforces Round #520 (Div. 2)
Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> u ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #520 (Div. 2) B. Math 唯一分解定理+贪心
题意:给出一个x 可以做两种操作 ①sqrt(x) 注意必须是完全平方数 ② x*=k (k为任意数) 问能达到的最小的x是多少 思路: 由题意以及 操作 应该联想到唯一分解定理 经过 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #595 (Div. 3)D1D2 贪心 STL
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
- Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索
https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...
- Codeforces Round #303 (Div. 2) D 贪心
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #207 (Div. 1)B(数学)
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...
随机推荐
- 简单封装的Log4net
1. [代码]使用 log = new Logger(this.GetType());log.Info("Hello world.");2. [代码]第二个版本,修复了Co ...
- Python基础-修改excel中内容
from xlutils.copy import copy import xlrd import os #1.打一要修改的excel #2.再打开另一个excel #3.把第一个excel里面修改东西 ...
- 1143. Lowest Common Ancestor (30)
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...
- 求解范围中 gcd(a,b)== prime 的有序对数
题目: 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入: 一个整数N. 输出: 如题. Sample Input 4 Sample Output ...
- 【LeetCode】018 4Sum
题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...
- Django来敲门~第一部分【4. 创建第一个模块应用】
成若缺,其用不弊.大盈若冲,其用不穷.大直若屈.大巧若拙.大辩若讷.静胜躁,寒胜热.清静为天下正 ——老子<道德经> 本章内容 创建应用(app) 开发第一个视图(View) URL访问配 ...
- cloudera上面安装Spark2.0
Cloudera默认值是提供Spark1.6的安装,下面介绍如何来安装spark2.1 1. csd包:http://archive.cloudera.com/spark2/csd/ 2. parce ...
- UIButton常见用法
//UIButton是iOS中用来响应用户点击的控件,既可以显示文字,也可以显示图片,也可以处理用户交互 //UIButton的创建,一般采用类方法来创建,不需要释放 //UIButton 也是UIC ...
- 发布倒计时!JDK11为我们带来哪些新特性?
今年7月底,JDK11已经进入了Rampdown Phase Two阶段,这标志着该版本所有特性已经被冻结,不会有新的JEP会加入版本中. 这一阶段将会修复P1–P2级BUG,之后,JDK11预定于今 ...
- DataTable列查询加排序
DataTable列查询加排序 DataRow[] drArray = dt.Select("ANLYCOM_ID='" + chSPrdtStblAnly.AnlyComId + ...