HDU 1061 找规律

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1061
题目求最左边的一位。这就明显是找个规律打表了。因为只和最后一位有关。他又是只有n去乘。

#include<bits/stdc++.h>
#define INF 1e18
#define inf 1e9
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;

int t[11][5]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};
int main(){
    int k;
    ll n;
    cin>>k;
    while(k--){
        cin>>n;
        int id2 = (n-1)%4;
        int id1 = n%10;
        cout<<t[id1][id2]<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38987374/article/details/79607814
今日推荐