zoukankan      html  css  js  c++  java
  • codeforces 869B

    B. The Eternal Immortality
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    这题的思路还是挺好想的,只要对个位进行运算就行了,当个位为0的时候,直接跳出。

    附高手ac代码:

    #include <iostream>
    using namespace std;
    long long a, b, s=1, i;
    int main() {
        cin>>a>>b;
        for(i=a+1; i<=b && s; i++) s = s*i%10;
        cout<<s;
        return 0;
    }
    

      

    附我ac代码(鲜明对比啊):

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #define ll long long
    using namespace std;
    const ll mod = 10;
    ll qadd(ll a,ll b) {
    	ll res = 0;
    	while(b) {
    		if(b&1) 
    			res = (res+a)%mod;
    		b>>=1;
    		a = (a+a)%mod;
    		
    	}
    	return res;
    }
    int main() {
    	ios::sync_with_stdio(false);
    	ll a,b;
    	ll ans=1;
    	cin>>a>>b;
    	if(a==0) a=1;
    	if(b==0) b=1;
    	if(b-a>=10) puts("0");
    	else {
    		while(a!=b) {
    		//	cout<<1<<endl;
    			ans=qadd(ans,b)%mod;
    		//	cout<<ans<<" "<<b<<endl;
    			b--;
    		}
    		cout<<ans<<endl;
    	}
    //	ans=ans%mod;
    	
    	return 0;
    }
    

      

  • 相关阅读:
    luoguP3806 【模板】点分治1
    BZOJ 4176: Lucas的数论 莫比乌斯反演 + 杜教筛
    BZOJ 3994: [SDOI2015]约数个数和 莫比乌斯反演
    CF1037H Security 后缀自动机 + right集合线段树合并 + 贪心
    BZOJ 2226: [Spoj 5971] LCMSum 莫比乌斯反演 + 严重卡常
    BZOJ 4408: [Fjoi 2016]神秘数 主席树 + 神题
    BZOJ 4804: 欧拉心算 欧拉函数
    BZOJ 3930: [CQOI2015]选数 莫比乌斯反演 + 杜教筛
    html基础总结
    对于房天下租房信息进行爬取
  • 原文地址:https://www.cnblogs.com/zmin/p/7634565.html
Copyright © 2011-2022 走看看