• 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);
        }
    }
    




     
  • 相关阅读:
    Python学习笔记(三): 收集参数
    Effective Java 之-----关于延迟初始化
    Effective Java 之-----返回零长度的数组或集合而不是null
    CSS学习笔记(一):定位与溢出
    Python学习笔记(二):字典
    Effective Java 之-----静态工厂与构造器
    Effective Java 之-----for-each循环优于传统的for循环
    Python学习笔记(一):列表和元组
    Effective Java 之-----精确的答案与double&float
    Effective Java 之-----消除过期的对象引用
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053332.html
Copyright © 2020-2023  润新知