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

    目录 Python,那些不可不知的事儿 Python简介 Python环境搭建 从Hello World开始 Python中的数据类型 函数 模块 面向对象 More Python,那些不可不知的事儿 ...

  2. KVO的使用三:基于runtime实现KVO

    苹果的KVO原理通过isa-swizzling技术实现,本质实现逻辑是在runtime时添加一个子类,重写set方法进行操作,现在我们也基于runtime来实现一个KVO. 首先新建一个Person类 ...

  3. Python 运维之路

    第一章:Python基础知识 1.Python 变量了解 .Python 二进制 .Python 字符编码 4.Python if条件判断 5.Python while循环 6.Python for循 ...

  4. Bigger-Mai 养成计划,Python基础巩固一

    本日复习内容 Py2与Py3的区别:Py2:print()直接写字符串,不用加括号Py3:print()必须加括号,某些库改名了.还有谁不支持Py3:Twisted:具体能感知的大改动并不多 老生常谈 ...

  5. 从0开始的Hexo主题制作

    从0开始的Hexo主题制作 从零开始制作 Hexo 主题 H2O主题 先坑着

  6. 【POJ 1179】Polygon

    [原题链接]传送门 [题解思路] 1.第一感觉没有其他做法,想到动态规划,去环,区间dp 2.f[l,r]表示[l,r]内的最大值,考虑转移 3.最大值分加法和乘法,其中乘法不一定由两个要求合并的区间 ...

  7. bzoj2194 快速傅立叶之二 ntt

    bzoj2194 快速傅立叶之二 链接 bzoj 思路 对我这种和式不强的人,直接转二维看. 发现对\(C_k\)贡献的数对(i,j),都是右斜对角线. 既然贡献是对角线,我们可以利用对角线的性质了. ...

  8. html2canvas文字重叠(手机端)

    发现情况: 1.设置文字居中,文字自动换行后文字有重叠   text-align: center; 解决办法: text-align: left; text-align: justify;等 2.使用 ...

  9. ubuntu安装nvidia显卡驱动

    朋友挖矿,需要给Ubuntu(16.04版本)系统安装nvidia的显卡驱动,请我帮忙.最开始是进行手动安装.无奈的是安装完后进不了图形化界面.今天正好有时间,找了个硬盘装了个Ubuntu进行测试,成 ...

  10. leetcode算法题01

    最近求职需要重新刷算法题,从今天开始每天至少做一个leatcode的题 如果有更好的算法或者换了语言也会更新 题目: 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只 ...