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. ColumnStore完整验证指南之安装与启动停止

    官方文档https://mariadb.com/kb/en/library/mariadb-columnstore/ 推荐使用最新1.2.x最新版本. 先决条件 yum -y install boos ...

  2. Linux 内存泄漏检查工具 valgrind

    抄自<从零开始的JSON库教程>,先mark一下,以后再慢慢研究. ======== 引用分割线 ======== 在 Linux.OS X 下,我们可以使用 valgrind 工具(用 ...

  3. range 小数据池介绍

    1.range 2.小数据池 1. range 范围 [起始位置:终止位置:步长]range(起始位置,终止位置,步长) #顾头不顾尾 3.小数据池 小数据池,也称为小整数缓存机制,或者称为驻留机制等 ...

  4. 剑指offer(65)矩阵中的路径

    题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵中 ...

  5. sql 中 and 和 or的坑

    请参考以下链接 https://blog.csdn.net/u011064736/article/details/70257366

  6. 复旦大学2018--2019学年第一学期(18级)高等代数I期末考试第七大题解答

    七.(本题10分)  设 $V$ 为 $n$ 维线性空间, $\varphi,\psi$ 是 $V$ 上的线性变换, 满足 $\varphi\psi=\varphi$. 证明: $\mathrm{Ke ...

  7. LeetCode 05 最长回文子串

    题目 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意: ...

  8. Js浮点运算存在精度问题

    记得在某一次项目中,运用js进行一系列算数运算,计算中会存在浮点类型,就单纯的进行了计算,最后在测试过程中,主管在核对数据的时候发现计算的结果是有问题的,于是就很纳闷,在网上搜索找到了答案  ,htt ...

  9. cordova自定义插件的创建过程

    最近学习了cordova插件,记录一下大概的过程,仅供参考. 前期的配置就不记录了网上好多. 在简书上从新写了一个更详细的cordova插件教程,有需要的可以点这里进去看看. 第一步 创建一个cord ...

  10. psycopg2+postgis+pgAdmin4

    基于docker的postgres 部署见这篇 https://www.cnblogs.com/xuanmanstein/p/7742647.html 连接数据库 import psycopg2cla ...