ZOJ 3785 What day is that day? 数论

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 ([email protected])
  * @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;
}
时间: 2024-10-05 23:55:12

ZOJ 3785 What day is that day? 数论的相关文章

zoj 3785 What day is that day?

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272 打表找规律. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define LL long long 5 using namespace std; 6 const int mod=7; 7 char g[][10]={"Saturday",

zoj 3621 Factorial Problem in Base K 数论 s!后的0个数

Factorial Problem in Base K Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3621 Description How many zeros are there in the end of s! if both s and s! are written in base k which is not nece

ZOJ 3785

What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple test cases. The first line of input contains an integer T indicating the number o

【ZOJ】3785 What day is that day? ——浅谈KMP应用之ACM竞赛中的暴力打表找规律

首先声明一下,这里的规律指的是循环,即找到最小循环周期.这么一说大家心里肯定有数了吧,“不就是next数组性质的应用嘛”. 先来看一道题 ZOJ 3785 What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple tes

2014浙江省赛

ZOJ 3777 Problem Arrangement 状态压缩DP,种数DP,dp[s][m]代表当前被占位置的集合分数为m的方案数,父母是总数n!,记忆化搜索好写 by fd ZOJ 3785 What day is that day? 等比数列,逆元,快速幂,当然可以暴力找循环节,有mod肯定有循环节,因为x^y%7 等价于(x%7)^y,所以可以分成6个第比数列,如下 1^1,2^2,3^3,4^4,5^5,6^6,0^7 1^8,2^9,3^10,4^11,5^12,6^13,0,^

2014 Super Training #4 G What day is that day? --两种方法

原题: ZOJ 3785 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3785 题意:当天是星期六,问经过1^1+2^2+3^3....+n^n天后是星期几? 这题开始以为是这种式子的求和问题,翻了半天没翻到公式.结果没搞出来.后来发现有两种方法. 第一种方法: 找规律 打表可以看出,这些数的结果出现42一循环,所以直接就处理出前42个,后面的就用前面的. 代码: #include <iostream> #inclu

[暑假集训]区域赛套题集

2014-07-03 [浙江第11届省赛]ZOJ 3785 What day is that day?  (打表找循环节) [暑假集训]区域赛套题集

ZOJ 1136 Multiple(BFS + 数论 同余剪枝 搜索数字的倍数 )

ZOJ Problem Set - 1136 Multiple Time Limit: 10 Seconds Memory Limit: 32768 KB a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the smallest strictly positive mult

Happy Equation ZOJ - 4123 (数论)

题目链接:ZOJ - 4123  题目大意:给你a和p,然后问你[1,2^p]中满足那个等式的值有多少个. 具体思路: 具体的证明:https://blog.csdn.net/v5zsq/article/details/79325038 打表发现当a为奇数的时候答案为1.当a为偶数的时候,x也必须为偶数. 然后我们将a分解为2*t.然后a^x就等于 (2^x)*(t^x).当x大于p的时候,此时取模后一定为0.对于所以在x属于[0,p]这段区间暴力算. 然后我们将b分解为(2^k)*t.然后b^