链接

[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的更多相关文章

  1. Divisor Subtraction

    Description You are given an integer number nn. The following algorithm is applied to it: if n=0, th ...

  2. CodeForces-1076B Divisor Subtraction 找规律

    题目链接:https://vjudge.net/problem/CodeForces-1076B 题意: 题目要求给定一个数,要求每次减去其最小素因数(既是素数又是其因数),问直到n=0需要做几次运算 ...

  3. CF1076B Divisor Subtraction 题解

    Content 给定一个数 \(n\),执行如下操作: 如果 \(n=0\) 结束操作. 找到 \(n\) 的最小质因子 \(d\). \(n\leftarrow n-d\) 并跳到操作 \(1\). ...

  4. Educational Codeforces Round 54 (Rated for Div. 2) Solution

    A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...

  5. 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 ...

  6. 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 ...

  7. CoderForces Round54 (A~E)

    ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字 ...

  8. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

  9. Codeforces Edu Round 54 A-E

    A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str ...

随机推荐

  1. Head First Android --- Enable USB debugging on your device

    1. Enable USB debugging on your device    On your device, open “Developer options” (in Android 4.0 o ...

  2. 【PAT】B1040 有几个PAT(25)(25 分)

    一点25分的样子都没有 #include<cstdio> #include<string.h> using namespace std; int main(){ long lo ...

  3. 【PAT】B1053 住房空置率(20 分)

    #include<cstdio> #include<string.h> #include<algorithm> using namespace std; int m ...

  4. nginx基础知识总结

    1.nginx的工作模式 master/worker工作模式: 一个master进程: 负载加载和分析配置文件.管理worker进程.平滑重启升级等. 一个或多个worker进程 处理并响应用户请求 ...

  5. 【Excel】SUMIF函数的兼容性

    兼容性非常强的两个函数 SUMIF() 说兼容性,当然得说SUMIF了. 来,我们先举个例子. 现有一个表格,算起来只有"科目划分"."发生额"两列内容,但是折 ...

  6. 怎样将本地web项目部署到腾讯云服务器上?

    怎样将本地web项目部署到腾讯云服务器上? 1.本地计算机的工作: (1).用eclipse新建一个web项目,然后在webcontent下新建一个index.html,然后在本地部署到Tomcat服 ...

  7. 随机生成&部门匹配

    整体概况 1.完整程序概况 (1)程序整体构架 (2)生成程序模型 (3)匹配算法模型 (4)生成结果评估 (5)命名规范 (6)先期和后期分工 2.心路历程与对全新的java认识(心得体会篇) (1 ...

  8. 关于解决Python中requests模块在PyCharm工具中导入问题

    问题引入: 今天在学习Python网络请求的时候,导入requests模块时一直报红色波浪线,如图: 反复折腾,一直以为自己没有安装requests模块,反复安装反复卸载: 安装方法: 首先 cd 进 ...

  9. WPFのImage控件souce引入的方法总结

    1.后台代码相对路径添加(若为绝对路径,换UriKind的属性即可) BitmapImage testBitmapImage = new BitmapImage(new Uri(@"\bin ...

  10. CPU指令分类

    指令可以分为三类: 有运算单元参与:compq.subq 无运算单元参与:jge.movq MOV指令可以在CPU内或CPU和存储器之间传送字或字节,它传送的信息可以从寄存器到寄存器,立即数到寄存器, ...