码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ 3785 What day is that day? 数论

时间:2017-03-30 21:50:38      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:auth   target   toolbar   code   class   efi   处理   .com   ack   

LINK: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3785

题意:求 \(1^1+2^2+3^3+…+n^n\) 加1模7的值

思路:其实这题是找规律题...说数论是不甘心,这题卡了好久,借助python打表发现 指数每6循环 n值每7循环 6*7=42 但每42个数后它们的排列就会发生改变,共改变7次,所以总循环周期为42*7=294,预处理记录一下就好。

/** @Date    : 2017-03-23-23.08
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version :
  */
#include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

int rec[300];
LL sum[300];
char day[8][10] = {"Sunday",
    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" , "Saturday", "Sunday"};
int main()
{
    rec[0] = 0;
    sum[0] = 0;
    for(int i = 1; i <= 42*7; i++)
    {
        int r;
        if(i % 7 == 0)
            r = 0;
        else
            r = (int)pow(i%7, i%6) % 7;
        rec[i] = r;
        sum[i] = sum[i - 1] + rec[i];
    }
    int T;
    LL n;
    cin >> T;
    while(T--)
    {
        scanf("%lld", &n);
        LL x = n / (42*7);
        LL y = n % (42*7);
        LL ans = (x * sum[294] + sum[y] + 6) % 7;
        printf("%s\n", day[ans]);
    }

    return 0;
}

 

ZOJ 3785 What day is that day? 数论

标签:auth   target   toolbar   code   class   efi   处理   .com   ack   

原文地址:http://www.cnblogs.com/Yumesenya/p/6648397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!