⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1061 rightmost digit.cpp

📁 威士忌的HDU题解.大概有260多题的源码。对于学习非常有好处。
💻 CPP
字号:
/*
1061 Rightmost Digit
Time Limit : 1000 ms  Memory Limit : 32768 K  Output Limit : 1024 K

GUN C++
*/
//验证何时出现重复,在根据n的值确定最后一位在重复中出现的位置
#include <iostream.h>
using namespace std;

const int NMAX=1000000000;

int main()
{
    int t,n;
    int lastdigit,last[10]={0},now;
    while(cin>>t)
    {
        for(int ca=0;ca<t;ca++)
        {
            cin>>n;
            lastdigit=n%10;
            last[0]=lastdigit;
            now=1;last[1]=lastdigit*lastdigit%10;
            while(last[0]!=last[now])
            {
                now++;
                last[now]=last[now-1]*lastdigit%10;
            }
            lastdigit=last[(n-1)%now];
            cout<<lastdigit<<endl;
        }
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -