A.Orac and Factors
先上题目链接:https://codeforces.com/contest/1350/problem/A
题目大意:给定一个数n,f(n)表示n的最小因子数(1除外),在给定次数k,每次计算f(n)+n作为新一轮的n,求最后结果。
解题思路:这算是一道签到题,需要一点点小技巧的暴力,莽撞上去可能会超时哦。先试着输出几个数字观察一下,例如(5 1
5 2
5 3
5 4
)
你会发现,从第二个开始,每个都和前面相差2,因为当k>=2时,不管怎么加,都会有一个因子为2,
所以,当k==1时,结果ans=n+f(n);
当k>=2时,ans=n+f(n)+(k-1)*2;
AC代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define ll long long
using namespace std;
int main()
{int t;scanf("%d",&t);ll n,k;for(int ii=0;ii<t;ii++){scanf("%lld%lld",&n,&k);ll ans=n;for(int i=2;i<=n;i++){if(n%i==0){ans+=i;break;}}ans=ans+2*(k-1);printf("%lld\n",ans);} return 0;}
A.Orac and Factors相关推荐
- Orac and Factors
Orac is studying number theory, and he is interested in the properties of divisors. For two positive ...
- 1096 Consecutive Factors
1. 对于题目描述中 list the smallest sequence of the consecutive factors 正确理解是:如果有多组连续因子,输出开头因子最小的那个序列(一开始理解 ...
- Error in Math.factor() : ‘sqrt’ not meaningful for factors
Error in Math.factor() : 'sqrt' not meaningful for factors 目录 Error in Math.factor() : 'sqrt' not me ...
- Error in contrasts can be applied only to factors with 2 or more levels
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only ...
- Error in Math.factor(x) : ‘abs’ not meaningful for factors
Error in Math.factor(x) : 'abs' not meaningful for factors Error in Math.factor(x_fac): 'abs' not me ...
- R语言数据类型:Logical、Numeric、Integer、Complex、Character、Vectors、Lists、Matrices、Arrays、Factors、DataFrames
R语言数据类型:Logical.Numeric.Integer.Complex.Character.Vectors.Lists.Matrices.Arrays.Factors.DataFrames 通 ...
- PAT甲级1096 Consecutive Factors :[C++题解]连续的因子、约数
文章目录 题目分析 题目链接 题目分析 来源:acwing 题意重述:1个正整数N的因子中可能存在若干连续的数字.比如 N =630 ,N = 3 * 5 * 6 *7,这里连续的因子是5 *6 * ...
- PAT甲级1059 Prime Factors :[C++题解]分解质因子
文章目录 题目分析 题目链接 题目分析 暴力求质因数 下面i就是质因子,s是质因子i的阶数. 暴力的时间复杂度O(n),会超时 void divide(int n){for(int i=2;i< ...
- 4kyu Sum by Factors
4kyu Sum by Factors 题目背景: Given an array of positive or negative integers I= [i1,-,in] you have to p ...
最新文章
- 遂宁专业计算机学校,遂宁计算机专业中职学校哪家强
- PYTHON1.day01
- JS 设计模式 四(单例)
- Leetcode PHP题解--D57 762. Prime Number of Set Bits in Binary Representation
- adc0832对光电二极管进行数据采集_实验十adc0832数模转换的显示
- 鸿蒙系统突破,华为解锁新成就!新系统用户突破1亿,鸿蒙系统也传来了新消息...
- 『 效率工具 』Spring Boot版的轻量级代码生成器,减少70%以上的开发任务
- chap01 .net 基本框架介绍
- java Launcher源码_Launcher3源码浅析(5.1)--Launcher.java
- web浏览器_微软低头,Chrome 一统浏览器!
- EPI_H/EPI_V(边缘保持指数,matlab 矢量化编程)
- ajax异步数据加载
- 微星主板节能模式怎么关闭_微星正设计一套易用化BIOS 根据散热器自动调节性能释放_笔记本新闻...
- python常用模块之os
- Web前端工程师 VS 前端工程师?What?
- LIF-Seg 激光雷达与相机图像融合的三维激光雷达语义分割
- Qt中mouseMoveEvent在MainWindow中使用
- button按钮居中
- 动态下载苹果提供的多种中文字体
- Linux redhat8.0 NFS共享目录
热门文章
- layui 弹出层里面添加表格数据
- solidworks出现操作系统当前的配置不能运行此应用程序
- 论文笔记34 -- (自动驾驶)【CVPR2021】SE-SSD: Self-Ensembling Single-Stage Object Detector From Point Cloud
- ios jenkins配置_ios jenkins从0快速配置
- 门诊计算机管理制度,诊所信息系统管理制度
- .Net执行SQL/存储过程之易用轻量工具
- 2D: 传统目标检测算法综述
- 2021-05-18 英语单词总结
- 计算机速录专业论文,速录论文10篇_发表之家
- iphonexs订阅显示无法连接服务器,iPhone XS/XS Max 无法连接到 App Store 怎么解决?