Codeforces 1076B Divisor Subtraction

线性筛法,数学问题,找规律。 

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.

Examples

input

Copy

5

output

Copy

1

input

Copy

4

output

Copy

2

Note

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.

 

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int t;
int a[100000];
bool vis[100000];
void Init() {
	memset(vis,true,sizeof(vis));
	t=0;
	for (int i=2; i<100000; i++) 
	{
		if (vis[i]==true) 
		{
			a[t++] = i;
			for (int j=i+i; j<100000; j+=i)
			vis[j] = false;
		}
	}

}

int main() {
	long long n,ans=0;
	Init();
	cin>>n;
	for (int i=0; i<t; i++) 
	{
		if (n%a[i]==0 && (n-a[i])%2==0) 
		{
			cout<<(n-a[i])/2+1<<endl;
			return 0;
		} 
		else if (n%a[i]==0) 
		{
			cout<<n/a[i]<<endl;
			return 0;
		}
		
	}cout<<1<<endl;

	return 0;
}




 

转载于:https://www.cnblogs.com/Romantic-Chopin/p/10253028.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值