当前位置:网站首页>E. Singhal and numbers (prime factor decomposition)
E. Singhal and numbers (prime factor decomposition)
2022-07-05 20:23:00 【Dimple】
https://codeforces.com/gym/102767/problem/E
The question
Give a number n, You can choose less than n As a factor of N.
- If N Prime number , So the answer is A + X N A + \frac{X}{N} A+NX;
- If N Is the sum , So the answer is B + X N B + \frac{X}{N} B+NX;
- If N by 1, So the answer is C + X N C + \frac{X}{N} C+NX.
ask , What is the minimum answer ?
Ideas
To minimize the answer , Be sure to find the largest prime factor , The largest combining factor .
Prime factor decomposition finds the maximum prime factor ,O( n \sqrt{n} n).
In order to find the maximum composite number , Sure First find the maximum factor :n / Minimum prime factor .
- If the maximum factor is prime , It means that there is no maximum combining factor .
- Otherwise, the maximum factor is the maximum resultant factor .
Note that the factor in this question should be less than n, So we can make a special judgment first n In the case of prime numbers .
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a, b, c;
bool isPrim(int x){
if(x == 0 || x == 1) return 0;
for(int i=2;i<=x/i;i++)
{
if(x % i == 0) return 0;
}
return 1;
}
signed main(){
Ios;
cin >> T;
while(T--)
{
cin >> n;
cin >> a >> b >> c;
if(isPrim(n)){
cout << c + n << endl;
continue;
}
int mprim = -1, mcom = -1;
int minprim = -1;
int t = n;
for(int i=2;i<=t/i;i++)
{
if(t % i == 0)
{
while(t % i == 0) t/=i, mprim = i;
if(minprim == -1) minprim = i;
}
}
if(t != 1) mprim = t;
int min1 = 1e18, min2 = 1e18, min3 = 1e18;
min1 = a+n/mprim;
mcom = n/minprim;
if(!isPrim(mcom)) min2 = b+n/mcom;
min3 = c+n;
int ans = min(min(min1, min2), min3);
cout << ans << endl;
}
return 0;
}
边栏推荐
- Codeforces Round #804 (Div. 2) - A, B, C
- Ros2 topic [01]: installing ros2 on win10
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
- Leetcode brush questions: binary tree 18 (largest binary tree)
- Cocos2d-x项目总结中的一些遇到的问题
- .Net分布式事務及落地解决方案
- Informatics Olympiad 1338: [example 3-3] hospital setting | Luogu p1364 hospital setting
- What is PyC file
- 走入并行的世界
猜你喜欢
About the priority of Bram IP reset
2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Ros2 topic [01]: installing ros2 on win10
基础篇——配置文件解析
[Yugong series] go teaching course in July 2022 004 go code Notes
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)
Mysql频繁操作出现锁表问题
随机推荐
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
强化学习-学习笔记4 | Actor-Critic
c语言oj得pe,ACM入门之OJ~
CVPR 2022 | 常见3D损坏和数据增强
C language OJ gets PE, OJ of ACM introduction~
19 Mongoose模块化
About the priority of Bram IP reset
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
Leetcode(347)——前 K 个高频元素
Schema and model
Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
14、Transformer--VIT TNT BETR
Mongodb/ document operation
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
Leetcode(695)——岛屿的最大面积
CCPC 2021威海 - G. Shinyruo and KFC(组合数,小技巧)
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development