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. 算法(第四版)C# 习题题解——2.5

    写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 查找更方便的版本见:https ...

  2. 算法(第四版)C# 习题题解——2.1

    写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...

  3. 20175307《Java程序设计》第8周学习总结

    教材学习内容总结 本周学习<Java程序设计>第十五章: 泛型: 泛型(Generics)的主要目的是可以建立具有类型安全的集合框架,如链表.散列映射等数据结构. 泛型类声明:class ...

  4. Spring Boot 数据库连接池 HikariCP

    简介 HikariCP 来源于日语,「光」的意思,意味着它很快!可靠的数据源,spring boot2.0 已经将 HikariCP 做为了默认的数据源链接池. 官网详细地说明了HikariCP所做的 ...

  5. 安装linux14.04

    一.制作Ubuntu启动盘 1.将空的优盘格式化当做启动盘,下载UltralSO并安装,安装成功后打开,点击工具栏中的第二个打开镜像文件工具(或通过文件-打开的方式打开),选择下载好的Ubuntu镜像 ...

  6. 防cc攻击策略

    黑客攻击你的网站,会采取各种各样的手段,其中为了降低你网站的访问速度,甚至让你的服务器瘫痪,它会不断的刷新你的网站,或者模拟很多用户同一时间大量的访问你的网站, 这就是所谓的CC攻击,这就需要我们在程 ...

  7. LeetCode 05 最长回文子串

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

  8. CentOS7.4用yum安装并配置MySQL5.7

    1.配置YUM源 下载MySQL源安装包 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 安装MySQ ...

  9. Python开发 基础篇

    2019-02-01 产生验证码: 用户输入的值和显示的值相同时显示Correct,否则继续生成随机验证码等待用户输入 def check_code(): import random checkcod ...

  10. java获取本机ip地址(写出来的)

    /** * @author 豪弟 * @param request * @return * @throws IOException */ public final static String getI ...