zoukankan      html  css  js  c++  java
  • Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

    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.

    Examples
    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.

     


      题目大意 给定a和b求b的阶乘除以a的阶乘的商的末尾数字。

      显然,当a和b的差大于等于10的时候结果为0.

      当a和b的差小于10的时候,暴力计算就好了(当然,不是把a!和b!)。

    Code

     1 /**
     2  * Codeforces
     3  * Problem#869B
     4  * Accepted
     5  * Time: 30ms
     6  * Memory: 0k 
     7  */ 
     8 #include <bits/stdc++.h>
     9 #ifndef WIN32
    10 #define Auto "%lld"
    11 #else
    12 #define Auto "%I64d"
    13 #endif
    14 using namespace std;
    15 
    16 long long a, b;
    17 
    18 inline void init() {
    19     scanf(Auto""Auto, &a, &b);    
    20 }
    21 
    22 inline void solve() {
    23     if(b - a > 10)    puts("0");
    24     else {
    25         int res = 1;
    26         for(int i = b % 10, c = 0; c < b - a; c++, i = (i + 9) % 10) {
    27             res = (res * i) % 10;
    28         }
    29         printf("%d
    ", res);
    30     }
    31 }
    32 
    33 int main() {
    34     init();
    35     solve();
    36     return 0;
    37 }
  • 相关阅读:
    asp.net 页面元素分析搜集
    ASP.NET AJAX深入浅出系列UpdatePanel的使用笔记(上)
    用sql语句来管理数据库日志问题
    C# .NET学习网站(转)
    Visual Studio .Net团队开发[转]
    sql 语句大全
    Word中快速操作的10个技巧
    嫁给程序员的好处
    关于手机病毒时代到来的担忧
    自己工作用过的SQL代码(1)
  • 原文地址:https://www.cnblogs.com/yyf0309/p/7635454.html
Copyright © 2011-2022 走看看