Description

You are given an integer number nn. The following algorithm is applied to it:

  1. if n=0, then end algorithm;
  2. find the smallest prime divisor d of n;
  3. subtract dd from n and go to step 1.

Determine the number of subtrations the algorithm will make.

Input

The only line contains a single integer nn (2≤n≤10^10).

Output

Print a single integer — the number of subtractions the algorithm will make.

Sample Input

Input
5
Output
1
Input
4
Output
2

Hint

In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.

In the second example 2 is the smallest prime divisor at both steps.

题解:给你一个数n,找它的最小素因子,每回减去,直到n=0,素因子均为奇数(除了2),奇-奇=偶,例如15,标准答案应该为7而不是5,在1e5内没有素因子时,答案为1。

代码如下:

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define memset(x,y) memset(x,y,sizeof(x))
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define debug(x) cout<<x<<" "<<endl
#define rson i << 1 | 1,m + 1,r
#define e 2.718281828459045
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define lowbit(x) (x&(-x))
#define lson i << 1,l,m
#define INF 0x3f3f3f3f
#define ll long long
#define mod 1001113
#define N 100000000
#define PI acos(-1)
#define eps 1.0e-6
#define maxn 27
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
//const int maxn=;
using namespace std; int main()
{
ll n;
cin>>n;
for(ll i=;i*i<=n;i++)
{
if(n%i==)
{
cout<<+(n-i)/<<endl;
return ;
}
}
cout<<""<<endl;
return ;
}

Divisor Subtraction的更多相关文章

  1. B. Divisor Subtraction

    链接 [http://codeforces.com/contest/1076/problem/B] 题意 给你一个小于1e10的n,进行下面的运算,n==0 结束,否则n-最小质因子,问你进行多少步 ...

  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. 我的web前端整理和学习

    知识点收藏:(边看.边记录.边写) 开直播学习:虎牙 待办事理>> 练习自我表达(把文章做成视频).技术学习总结(博客与公众号).跳出舒适圈. 前端知识体系:https://www.cnb ...

  2. 【题解】Luogu P2221 [HAOI2012]高速公路

    原题传送门 这道题还算简单 我们要求的期望值: \[\frac{\sum_{i=l}^r\sum_{j=l}^rdis[i][j]}{C_{r-l+1}^{2}}\] 当然是上下两部分分别求,下面肥肠 ...

  3. caffe特征层可视化

    #参考1:https://blog.csdn.net/sushiqian/article/details/78614133#参考2:https://blog.csdn.net/thy_2014/art ...

  4. 打包加载 AssetBundle

    1.先创建Asset序列化(单个文件夹所在文件夹路径,会遍历这个文件夹所有的Prefab,所有的Prefab名字不能重复,必须保证名字得唯一性),配置好ConfigAB表 /* ######### # ...

  5. 安装Office2016遇到“无法流式传输Office”问题

    安装Office2016遇到“无法流式传输Office”问题,请问如何解决 很抱歉,找不到所需的文件,请检查安装源是否可访问,然后再试. 错误代码:30068-39(2) ============== ...

  6. P4233 射命丸文的笔记

    思路 题目要求求的是哈密顿回路的期望数量,实际上就是哈密顿回路的总数/有哈密顿回路的竞赛图的数量 n个点的所有竞赛图中哈密顿回路的总数为 \[ (n-1)! 2^{\frac{n(n-1)}{2}-n ...

  7. List集合流处理类型小结

    本文为博主原创,未经允许不得转载 对应实体类 import lombok.Getter; import lombok.Setter; @Getter @Setter public class Stud ...

  8. 20165306 Exp0 Kali安装 Week1

    20165306 Exp0 Kali安装 Week1 实验要求 Kali 下载 安装 网络 共享 软件源 步骤一.下载Kali 根据网址https://www.kali.org/ 下载kali 点击 ...

  9. java - 策略模式、状态模式、卫语句,避免多重if-else(转)

    前言 当代码中出现多重if-else语句或者switch语句时.弊端之一:如果这样的代码出现在多处,那么一旦出现需求变更,就需要把所有地方的if-else或者switch代码进行更改,要是遗漏了某一处 ...

  10. linux如何查看所有的用户和组信息?

    cat /etc/passwd cat /etc/passwd查看所有的用户信息,详情如下图   [步骤二]cat /etc/passwd|grep 用户名 cat /etc/passwd|grep ...