zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 54 (Rated for Div. 2) B. Divisor Subtraction

    传送:B. Divisor Subtraction

    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

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

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

    Determine the number of subtrations the algorithm will make.

    Input

    The only line contains a single integer n n (2≤n≤10 10  2≤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 5 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0 0 .

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

    题解:一个数减去最小的质数之后的最小质数必然是2。知道这个,这个题就很明了了。

    分为两种: 一种是像5,3这种的质数,直接减自己,结果就是1。

                        另一种是非质数,找见第一个质数之后,用减去质数的数字/2就是还能继续减的次数然后还要加1,因为减去第一个质数的时候有一次步骤。

    如 n=21 变化如下:

     21—18—16—14—12—10—8—6—4—2—0

    结果是10

    #include <iostream>
    
    using namespace std;
    typedef long long ll;
    int main(){
        ll n; cin>>n;
        ll x;
        for(ll i=2;i*i<=n;i++){
            if(n%i==0){
                cout<<1+(n-i)/2<<endl;
                return 0;
            }
        }
        cout<<1<<endl;
        return 0;
    }
    
  • 相关阅读:
    vue 购买弹出框 动画
    vue 和animate.css 的动画使用
    获得url地址?后的参数
    Java 实现随机数组元素升降序
    java for循环实现九九乘法表
    java 随机生成字符串验证码
    Mysql插入值时,避免重复插入
    Mysql的unique和primary key
    2020 3.6日电话面试(某外包公司)
    Intellij IDEA配置javaweb项目
  • 原文地址:https://www.cnblogs.com/UUUUh/p/10284067.html
Copyright © 2011-2022 走看看