zoukankan      html  css  js  c++  java
  • 矩阵快速幂

    矩阵快速幂的学习:

    https://blog.csdn.net/wust_zzwh/article/details/52058209

    n>>1是指n的二进制数向右移一位

    n&1等价n%2

    https://vjudge.net/contest/231312#problem/F

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<cmath>
    typedef long long ll;
    using namespace std;
    ll ans=1;
    void quickpow(ll x,ll n)
    {
        ll res=x;
        while(n)
        {
            if(n%2==1)
            {
                ans*=res;
                res*=res;
                if(ans>9)
                    ans=ans%10;
                if(res>9)
                    res=res%10;
            }
            else
            {
                res*=res;
                if(res>9)
                    res=res%10;
            }
            n=n>>1;
        }
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            ans=1;
            ll n;
            scanf("%I64d",&n);
            quickpow(n,n);
            printf("%I64d
    ",ans);
        }
        return 0;
    }
    

      

    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    Uva
    Uva
    Uva
    Uva
    Uva
    Uva
    Uva
    Uva
    第二次结队编程作业
    第三次软件工程作业的总结
  • 原文地址:https://www.cnblogs.com/caijiaming/p/9267108.html
Copyright © 2011-2022 走看看