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




     
  • 相关阅读:
    jQuery教程1,隐藏p标签
    Google 和 Microsoft 对 jQuery 的支持都很好。
    在编辑器中自动换行
    调用存储过程的一些方法
    jQuery教程2隐藏p标签内容按钮
    文件的复制,移动,创建
    网站中access数据库的备份和恢复
    修改文件名称
    生成静态网页,函数,引用过程
    网页中打印文本文件
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053332.html
Copyright © 2011-2022 走看看