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? 数论
原文:http://www.cnblogs.com/Yumesenya/p/6648397.html