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 ...
随机推荐
- 鸟哥的 Linux 私房菜Shell Scripts篇(一)
参考: http://linux.vbird.org/linux_basic/0340bashshell-scripts.php#script_be http://www.runoob.com/lin ...
- Python3.5中安装Scrapy包时出现问题
在Python3.5中安装Scrapy第三方库 pip install Scrapy 安装到后面出现的这类错误: error: Microsoft Visual C++ 14.0 is require ...
- domain or business logic
Here are a few of the questions you should ask when writing business logic: ¡Do you fully understand ...
- SQL易错总结1
SQL易错总结1 进阶 select语句.select * 查询所有不规范,写出要查的属性.distinct慎用,性能消耗很大 like 模糊查询 ,空值判断是 is null 单行函数:lower( ...
- flask框架的教程--程序的基本结构[二]
一个简单的程序 from flask import Flask # 实例化app 对象 app = Flask(__name__) @app.route('/') def index(): retur ...
- SAP SQVI 快速浏览器
SQVI可向SQL一样连接多个表浏览数据. 1.输入T-CODE:SQVI. 2.新建一个新查询case 输入CASE 名.点击新建,在弹出的窗口中输入标题,在数据源中可选择单个表查询,或者选择表连接 ...
- PJ初赛复习日记
PA姑娘的PJ初赛复习日记 by Pleiades_Antares PJ初赛考试马上就要开始了(今年应该是10.13吧?),作为蒟蒻的我们怎么能不复习呢? 众所周知,复习方法有很多很多种-- 比如 ( ...
- 计算器和Menu
MainActivity.java import android.app.Activity; import android.content.Intent; import android.os.Bund ...
- synchronized关键字用法
看到网上很多讲synchronized关键字用法的文章,说的都很有道理,也很深刻,但是看完总感觉脑袋里还是有点乱乱的.经过一番自己的思考后,想从自己的思考角度出发,来说一说synchronized关键 ...
- BSOJ 4591 -- 【JLOI2015】城池攻占
Description 小铭铭最近获得了一副新的桌游,游戏中需要用m个骑士攻占n个城池. 这n个城池用1到n的整数表示.除1号城池外,城池i会受到另一座城池fi的管辖,其中fi 每个城池有一个防御值h ...