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




     
  • 相关阅读:
    修改tomcat的get方法的参数长度
    [转]修改hosts文件不起作用
    [转]solr DataImportHandler 解决mysql 表导入内存溢出问题
    plat模板修改记录
    Linux基本命令
    使用DTM ( Dynamic Topic Models )进行主题演化实验
    Stuts2的"struts.devMode"设置成true后,不起作用,仍需要重启tomcat
    R语言——绘图函数深入学习
    R语言——基本绘图函数
    Stem Cell 华人科学家
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053332.html
Copyright © 2011-2022 走看看