hud 1061Rightmost Digit

/........................................................................................................................................\

打表找规律,

m = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 ...

i = 1 4 7 6 5 6 3 6 9   0   1   6  3   6   5   6   7   4  9  0  1   4   7   6   5   6   3   6  9   0    ...

很明显是以20为周期的函数。

\......................................................................................................................................../


#include<stdio.h>
#include <iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<list>
#include<vector>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;

int main()
 {
      int n,t;
      int a[24]={0,1,4,7,6,5,
                 6,3,6,9,0,
                 1,6,3,6,5,
                 6,7,4,9,0};
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            int m=n%20;
            printf("%d\n",a[m]);
        }
      return 0;
 }


你可能感兴趣的:(HDU)