hdu1061 Rightmost Digit

说实话,这道题给人的感觉不难,虽然第一次提交的时候超时了一次,然后看了一下数据量,稍作修改,提交,A了,但现在还是不知道为什么A了,上网搜了各种题解,感觉和他们的还是不一样。

解题思路:因为它要求的就是最后结果的个位数,又因为它是n个n相乘的结果,我只要去n的个位数就够了,就是n对10取余,然后(n%10)相乘n次,每次又要对10取余,但发现数据量有点大,因为要循环n次相乘,再对循环次数做处理,让n对10000取余,就够了,这里我自己也有点不明白。

贴出代码:

#include <stdio.h>

int main()
{
    int n, T;
    int num;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &n);
        num = 1;
        for(int i = 0; i<n%10000; i++)    //对相乘的次数做处理
        {
            num = (num*(n%10))%10;     //求n的余数与它相乘,然后再取余
        }
        printf("%d\n", num);
    }
}

hdu1061 Rightmost Digit

时间: 2024-10-11 00:05:04

hdu1061 Rightmost Digit的相关文章

快速幂 HDU-1021 Fibonacci Again , HDU-1061 Rightmost Digit , HDU-2674 N!Again

1.   Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 77116    Accepted Submission(s): 34896 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11,

&lt;hdu - 1600 - 1601&gt; Leftmost Digit &amp;&amp; Rightmost Digit 数学方法求取大位数单位数字

1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * 10^x;其中x也是未知的: 两边取log10有:lg(n^n) = lg(a * 10^x); 即:n * lg(n)  - x = lg(a); 现在就剩x一个变量了,我们知道x是值n^n的位数-1,a向下取整就是我们要求的数: 所以 按着上面的推导式翻译成代码就可以了(注意:数值的范围和之间的

HDU 1061 Rightmost Digit

Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test ca

[HDOJ]Rightmost Digit

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 38642    Accepted Submission(s): 14558 Problem Description Given a positive integer N, you should output the most right digit of N

HDU_1061:Rightmost Digit

Problem Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.Each

HDOJ 1061 Rightmost Digit

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30543    Accepted Submission(s): 11624 Problem Description Given a positive integer N, you should output the most right digit of N

HDU 1061 Rightmost Digit(找规律)

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 43732    Accepted Submission(s): 16434 Problem Description Given a positive integer N, you should output the most right digit of

Rightmost Digit (求n^n最后一位)

Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test ca

HDU - 1061 - Rightmost Digit (快速幂取模!)

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 34329    Accepted Submission(s): 13091 Problem Description Given a positive integer N, you should output the most right digit of