栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3406 Last digit

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3406 Last digit

#include <iostream>#include <cstdio>#include <algorithm>#include <map>#include <vector>#include <cstring>#include <cmath>using namespace std;typedef long long ll;const int maxn = 7e4+10;int table[4][4]={6,2,4,8,      1,3,9,7,      1,7,9,3,      1,9,1,9,};int n,m;int getpow(int n,int p){    int q=p,res=0;    while(n>=q){res+=n/q;q*=p;}    return res;}int g(int n,int x){    if(n==0) return 0;    return n/10+(n%10>=x?1:0)+g(n/5,x);}int f(int n,int x){    if(n==0) return 0;    return f(n/2,x)+g(n,x);}int solve(){   int ans=1;   int pow_2=getpow(n,2)-getpow(n-m,2)-getpow(m,2);   int pow_5=getpow(n,5)-getpow(n-m,5)-getpow(m,5);   if(pow_2<pow_5) return 5;  else if(pow_2==pow_5) ans=1;   else ans*=table[0][(pow_2-pow_5)%4];   int pow_3=f(n,3)-f(n-m,3)-f(m,3);pow_3=(pow_3%4+4)%4;   int pow_7=f(n,7)-f(n-m,7)-f(m,7);   int pow_9=f(n,9)-f(n-m,9)-f(m,9);   ans=(ans*table[1][pow_3%4])%10;   ans=(ans*table[2][pow_7%4])%10;   ans=(ans*table[3][pow_9%4])%10;   return ans;}int main(){   while(cin>>n>>m){    cout<<solve()<<endl;   }   return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371926.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号