zoukankan      html  css  js  c++  java
  • codeforces 869B The Eternal Immortality

    The Eternal Immortality

    Even if the world is full of counterfeits, I still regard it as wonderful.

    Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
    The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
    Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b ≥ a this value is always integer.
    As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

    Input
    The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

    Output
    Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

    Example
    Input
    2 4
    Output
    2
    Input
    0 10
    Output
    0
    Input
    107 109
    Output
    2
    Note
    In the first example, the last digit of  is 2;
    In the second example, the last digit of  is 0;
    In the third example, the last digit of  is 2.

    题意是:求一个数的阶乘除以另一个数的阶乘的最后一位。
    思路是如果两个数的差大于九(或者五),最后一位肯定是0.如果不是的话就从a遍历到b求出最后一位。
    #include<algorithm>
    #include<stdio.h>
    #include<iostream>
    using namespace std;
    int main()
    {
        long long m,n;
        while(~scanf("%lld%lld",&n,&m))
        {
            long long ans=1;
            if((m-n)>9)
            {
                printf("0
    ");
                continue;
            }
            for(long long i=n+1;i<=m;i++)
            {
                ans*=i;
                ans%=10;
            }
            printf("%lld
    ",ans);
        }
    }
    




     
  • 相关阅读:
    Gradle with Kotlin (二) 项目、Java项目、父子、同级共享代码
    Gradle with Kotlin (一) 安装、DSL、任务、插件
    辛弃疾
    Remote Method Invoke
    Webpack (一) 选项和配置
    《芙蓉女兒誄》
    js 原型链之我见
    js 库
    Gradle
    Spring Boot 入门
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053332.html
Copyright © 2011-2022 走看看