B. Divisor Subtraction
链接
[http://codeforces.com/contest/1076/problem/B]
题意
给你一个小于1e10的n,进行下面的运算,n==0 结束,否则n-最小质因子,问你进行多少步
分析
显然n为偶数时,,就会一直-2,不是偶数的话可能是合数或者素数
只需要找根号n内就可以找到合数的最小质因子,否则就是质数
一个奇数-一个奇数一定是偶数,看代码吧
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n;
while(cin>>n){
bool flag=0;
ll i;
for(i=2;i*i<=n;i++)
if(n%i==0){
flag=1;
break;
}
if(flag) cout<<(n-i)/2+1<<endl;
else cout<<1<<endl;
}
return 0;
}
B. Divisor Subtraction的更多相关文章
- Divisor Subtraction
Description You are given an integer number nn. The following algorithm is applied to it: if n=0, th ...
- CodeForces-1076B Divisor Subtraction 找规律
题目链接:https://vjudge.net/problem/CodeForces-1076B 题意: 题目要求给定一个数,要求每次减去其最小素因数(既是素数又是其因数),问直到n=0需要做几次运算 ...
- CF1076B Divisor Subtraction 题解
Content 给定一个数 \(n\),执行如下操作: 如果 \(n=0\) 结束操作. 找到 \(n\) 的最小质因子 \(d\). \(n\leftarrow n-d\) 并跳到操作 \(1\). ...
- Educational Codeforces Round 54 (Rated for Div. 2) Solution
A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...
- Educational Codeforces Round 54 (Rated for Div. 2) ABCD
A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...
- codeforces1076 A.B.C.D.E
1076A 1076B 1076C 1076D 1076D A. Minimizing the String You are given a string s consisting of n low ...
- CoderForces Round54 (A~E)
ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字 ...
- Codeforces Educational Codeforces Round 54 题解
题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...
- Codeforces Edu Round 54 A-E
A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str ...
随机推荐
- 【记录】GIT 常用命令记录
1. 查看所有的提交版本,包含当你co到之前提交版本后依旧可以看到以前的日志 git log --graph --pretty=format:'%h -%d %s (%cr)' --abbrev-co ...
- 解决input框黄色背景问题(转)
input:-webkit-autofill { box-shadow: 0 0 0px 1000px white inset !important;} <form action="l ...
- Codeforces gym 101343 A. On The Way to Lucky Plaza【概率+逆元+精度问题】
2017 JUST Programming Contest 2.0 题目链接:http://codeforces.com/gym/101343/problem/A A. On The Way to ...
- python第五十课——多态性
animal.py class Animal: def __init__(self,name): self.name = name def eat(self): pass dog.py from an ...
- wifi 安卓手机
通过wifi向服务器端发送数据 https://www.cnblogs.com/zhaoxinshanwei/p/3573813.html http://www.hx-wl.com.cn/51wifi ...
- QT 11 鼠标键盘事件添加
鼠标事件 void mousePressEvent(QMouseEvent *event); //单击 void mouseReleaseEvent(QMouseEvent *event); //释放 ...
- 表情存储异常--mybatis抛出异常(java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for column 'name' at row 1)
文章参考 https://blog.csdn.net/junsure2012/article/details/42171035 https://www.cnblogs.com/WangYunShuai ...
- 导入其他python文件或者python文件的函数
from abc import xxx 从abc的py文件导入一个具体的函数或者类 import abc 直接导入文件 a.b写在同一个文件目录下,a要使用b,直接import就可以了
- Reflections - Java 8 - invalid constant type
异常说明 使用Reflections扫描的时候出现could not create class file from, 原因是invalid constant type: 18 异常堆栈: org.re ...
- AI 机器学习基础
深度学习是机器学习的一个特定分支. 1.学习算法 对于某类任务T和性能度量P, 2.线性回归 3.正规方程(normal equation) 4.监督学习(supervised learning) 5 ...