当前位置:网站首页>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;
}
边栏推荐
- CTF逆向基础
- Notes on key vocabulary in the English original of the biography of jobs (12) [chapter ten & eleven]
- Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
- 【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
- Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
- 基础篇——配置文件解析
- 3.3、项目评估
- Process file and directory names
- 1: Citation;
- Zero cloud new UI design
猜你喜欢

【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法

Leetcode brush question: binary tree 13 (the same tree)

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第四届北京国际青少年眼健康产业展会

Fundamentals - configuration file analysis
![[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)](/img/6d/110b87747f0a4be52da9fd49a05b82.png)
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)

实操演示:产研团队如何高效构建需求工作流?

14、Transformer--VIT TNT BETR

小程序全局配置

Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
随机推荐
A way to calculate LNX
document方法
小程序代码的构成
A solution to PHP's inability to convert strings into JSON
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
Ros2 topic [01]: installing ros2 on win10
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
Schema和Model
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
Unity editor extended UI control
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
小程序项目结构
leetcode刷题:二叉树14(左叶子之和)
2022年7月4日-2022年7月10日(ue4视频教程mysql)
About the priority of Bram IP reset
小程序全局配置
sun.misc.BASE64Encoder报错解决方法[通俗易懂]
Leetcode(695)——岛屿的最大面积