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+...+NN1^1 + 2^2 + 3^3 + ... + N^N11+22+33+...+NN days?

Input

There are multiple test cases. The first line of input contains an integer TTT indicating the number of test cases. For each test case:

There is only one line containing one integer N(1&lt;=N&lt;=1000000000)N (1 &lt;= N &lt;= 1000000000)N(1<=N<=1000000000).

Output

For each test case, output one string indicating the day of week.

Sample Input

2
1
2

Sample Output

Sunday
Thursday

Hint

A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.

Solve

对于1…N1 \dots N1…N,对于777取模后,可以转换成一大串0…60 \dots 60…6的循环,所以11+22+33+...+NN1^1 + 2^2 + 3^3 + ... + N^N11+22+33+...+NN可以转换成:11+22+33+…(N%7)N1^1+2^2+3^3+ \dots (N\%7)^N11+22+33+…(N%7)N,然后我们可以发现,这个式子的值是七个等比数列的前xxx项和的总和。每项公比为num7num^7num7,第一项为nnn^nnn(0≤n≤6)(0\leq n \leq 6)(0≤n≤6)

那么我们只需要统计出0…60\dots 60…6的个数,并利用等比数列的前nnn项和公式计算即可

百度了一下,发现似乎写麻烦了,貌似可以直接打表找规律?而且代码还特别短,想看短代码的自行百度吧,貌似没有找到我这种方法写的QAQ

Code

/*************************************************************************

	 > Author: WZY
> School: HPU
> Created Time: 2019-04-20 09:49:05 ************************************************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=(1<<30);
const ll INF=(1LL*1<<60);
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
int exgcd(int a,int b,int &x,int &y)
{
if(!b)
{
x=1;y=0;
return a;
}
else
{
int r=exgcd(b,a%b,y,x);
y-=x*(a/b);
return r;
}
}
int inv(int a,int n)
{
int x,y;
exgcd(a,n,x,y);
x=(x%n+n)%n;
return x;
}
int Pow(int a,int b,int c)
{
int res=1;
while(b)
{
if(b&1)
res=res*a%c;
a=a*a%c;
b>>=1;
}
return res;
}
int a[10];
int sum[10];
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int t;
// 计算第一项的值
for(int i=1;i<7;i++)
sum[i]=Pow(i,7,7);
cin>>t;
int n;
while(t--)
{
ms(a,0);
cin>>n;
// 统计0~6出现的个数
for(register int i=1;i<7;i++)
a[i]=n/7+(n%7>=i);
// 0忽略,初始值为1的个数
int ans=a[1];
int __=0;
for(register int i=2;i<7;i++)
{
// 利用前n项和公式+逆元计算对7取模的结果
int _=(Pow(i,i,7)*((Pow(sum[i],a[i],7)-1+7)%7)*inv(sum[i]-1,7)+7)%7;
__+=_;
if(a[i]==0)
break;
}
ans=(ans+__)%7;
int cnt=(6+ans)%7;
if(cnt==0)
cout<<"Sunday\n";
if(cnt==1)
cout<<"Monday\n";
if(cnt==2)
cout<<"Tuesday\n";
if(cnt==3)
cout<<"Wednesday\n";
if(cnt==4)
cout<<"Thursday\n";
if(cnt==5)
cout<<"Friday\n";
if(cnt==6)
cout<<"Saturday\n";
}
return 0;
}

ZOJ 3785:What day is that day?(数论)的更多相关文章

  1. ZOJ 3785 What day is that day?(今天是星期几?)

    Description 题目描述 It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? 今天是星期六,11 + ...

  2. ZOJ 3785 What day is that day?(数论:费马小定理)

    What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what da ...

  3. zoj 3785 What day is that day? (打表找规律)

    题目 思路:比赛的时候有想过找循环节,但是,打表打错了. 后来,看着过了挺多人,就急了, 看了一下别人的时间 耗时都挺长的,就以为不是找规律, 没想到真是找规律,不过,这个题的数据可能挺大的. AC代 ...

  4. zoj 3785 What day is that day?

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272 打表找规律. #include <cstdio> #incl ...

  5. 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/onli ...

  6. ZOJ 1489 2^x mod n = 1 数论

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=489 题目大意: 给你正整数n,求最小的x使得2^x mod n = 1. 思路 ...

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

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  8. 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律

    转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...

  9. 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+ ...

随机推荐

  1. 06 windows安装Python+Pycharm+Scrapy环境

    windows安装Python+Pycharm+Scrapy环境 使用微信扫码关注微信公众号,并回复:"Python工具包",免费获取下载链接! 一.卸载python环境 卸载以下 ...

  2. 案例 stm32单片机,adc的双通道+dma 内部温度

    可以这样理解 先配置adc :有几个通道就配置几个通道. 然后配置dma,dma是针对adc的,而不是针对通道的. 一开始我以为一个adc通道对应一个dma通道.(这里是错的,其实是我想复杂了) 一个 ...

  3. map/multimap深度探索

    map/multimap同样以rb_tree为底层结构,同样有元素自动排序的特性,排序的依据为key. 我们无法通过迭代器来更改map/multimap的key值,这个并不是因为rb_tree不允许, ...

  4. 【STM8】STM8S介绍(编程环境、烧录、芯片内容)(Vcap需要一个电容接地)

    这篇博客的介绍大纲 [1]我使用的开发板和烧录器 [2]编程环境 [3]烧录软件和界面 [4]芯片内容 [1]我使用的开发板和烧录器 首先,我用的是STM8S003F3P6这款开发板,淘宝上就有了,5 ...

  5. How does “void *” differ in C and C++?

    C allows a void* pointer to be assigned to any pointer type without a cast, whereas C++ does not; th ...

  6. Linux学习 - 文件特殊权限

    一.SUID权限(只针对文件) 只有可执行的二进制程序才能设定SUID权限 命令执行者要对该程序拥有x(执行)权限 1 拥有SUID的文件 /usr/bin/passwd 2 功能: 命令执行者(其他 ...

  7. 【Linux】【Shell】【Basic】Bash

    命令历史:shell进程会在其会话中保存此前用户提交执行过的命令: ------------------------------------------------------------------ ...

  8. pandas读取csv文件中文乱码问题

    1.为什么会出现乱码问题,用什么方式编码就用什么方式解码,由于csv不是用的utf-8编码,故不能用它解码. 常用的编码方式有 utf-8,ISO-8859-1.GB18030等. 2.中文乱码原因: ...

  9. 在写易买网时产生的错误 JSTL标签库中<c:choose></c:choose>不能放JSP页面<!-- -->注释

    最近在使用JSTL标签库的<c:choose>标签时候,发现在该标签体中加了JSP的<!-- -->注释时,总是会显示报错信息.错误的信息如下: org.apache.jasp ...

  10. pipeline input步骤

    目录 一.简介 二.input步骤复杂用法 三.获取上游pipeline信息 四.超时中止 一.简介 执行imput步骤会暂停pipeline,直到用户输入参数.这是一种特殊的参数化pipeline的 ...