Divisor Subtraction

Description

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

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

Determine the number of subtrations the algorithm will make.

Input

The only line contains a single integer nn (2≤n≤10102≤n≤1010).

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 55 is the smallest prime divisor, thus it gets subtracted right away to make a 00.

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

注意:判断一个数是否是素数只要找到sqrt(n)就行!因为例如24有一个约数是3,那么一定有另一个约数是8,这一对数分别在sqrt(24)的两边,如果从2找到sqrt(n)还找不到约数,那么之后的数里边也不会有了!

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI acos(-1.0)
#define eps 1e-6
using namespace std;
typedef long long LL;

LL prime(LL n)  /*判断一个数是否是素数*/
{
    for(LL i=2; i<=sqrt(n); i++) 
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}


LL check(LL n) /*找因子*/
{                          
    for(LL i=2; i<=n/2; i++)
    {
        if(n%i==0)
            return i;
    }
}

int main()
{
    LL n;
    cin>>n;
    if(n%2==0)
    {
        cout<<n/2;
    }
    else
    {
        if(prime(n))
        {
            cout<<"1"<<endl;
        }
        else
        {
            cout<<(n-check(n))/2+1;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值