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 of test cases. For each test case:

There is only one line containing one integer 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.

分析:运用费马小定理,简化运算并求出循环节

1^1     2^2     3^3     4^4     5^5     6^6     7^7
8^8 9^9 10^10 11^11 12^12 13^13 14^14
15^15 16^16 17^17 18^18 19^19 20^20 21^21
22^22 23^23 24^24 25^25 26^26 27^27 28^28
29^29 30^30 31^31 32^32 33^33 34^34 35^35
36^36 37^37 38^38 39^39 40^40 41^41 42^42
43^43 44^44 45^45 46^46 47^47 48^48 49^49
转化后-->>
1^1 2^2 3^3 4^4 5^5 6^6 0
1^2 2^3 3^4 4^5 5^6 6^1 0
1^3 2^4 3^5 4^6 5^1 6^2 0
1^4 2^5 3^6 4^1 5^2 6^3 0
1^5 2^6 3^1 4^2 5^3 6^4 0
1^6 2^1 3^2 4^3 5^4 6^5 0
1^1 2^2 3^3 4^4 5^5 6^6 0

#include<iostream>
#include<math.h>
#define ll long long
using namespace std;
int s[50];
void chose(ll x){
switch(x){
case 0:printf("Sunday\n");break;
case 1:printf("Monday\n");break;
case 2:printf("Tuesday\n");break;
case 3:printf("Wednesday\n");break;
case 4:printf("Thursday\n");break;
case 5:printf("Friday\n");break;
case 6:printf("Saturday\n");break;
}
}
int main()
{
int T;
ll n;
for(int i=1;i<=42;i++){
int a,p,sum=1;
p=(i%6)?i%6:6;
//为6的倍数情况下保留一个六
a=i%7;
for(int j=1;j<=p;j++)
sum=(sum*a)%7;
s[i]=(s[i-1]+sum)%7;
}
scanf("%d", &T);
while(T--){
scanf("%lld", &n);
ll ans=(n/42%7*s[42]%7+s[n%42])%7;
ans=(ans+6)%7;
chose(ans);
}
return 0;
}

最新文章

  1. Dojo前端开发框架与jQuery前端开发框架,对比分析总结
  2. springMVC发送邮件
  3. scrollView实现基础中心点缩放及与UIPageControl结合使用
  4. c# 压缩文件
  5. ubuntu 开机进入不了图形界面
  6. Java面试09|多线程
  7. junit搭配hamcrest使用
  8. HBase0.98使用ReplicationAdmin管理集群同步
  9. Android图表库MPAndroidChart(二)——线形图的方方面面,看完你会回来感谢我的
  10. 深度学习入门实战(一):像Prisma一样算法生成梵高风格画像
  11. [转]Redis配置文件详解
  12. C:\Users\Administrator\.IntelliJIdea2017.3\system\tomcat\Unnamed_08_upload\work\Catalina\localhost\ROOT这个错误是找不到temp文件
  13. elbow 求拐点
  14. java实现表格tr拖动
  15. 深入了解scanf()/getchar()和gets()/cin等函数
  16. [未解决:快速滑动collectionveiw请求数据崩溃]:unable to allocate 6553600 bytes for bitmap data
  17. gradlew 的https代理设定
  18. THE LAST ONE!! 2017《面向对象程序设计》课程作业八
  19. Centos7-Lvs+Keepalived架构
  20. struts2:多模块多配置文件开发

热门文章

  1. centos设置服务开机启动失败问题
  2. 第二节,mnist手写字体识别
  3. swap扩展
  4. hdfs命令get或者put提示找不到目录或文件
  5. Excel自动建组
  6. HAProxy详解(一):HAProxy介绍【转】
  7. EMOS之邮件服务器
  8. OninitDialog与OnCreate两个消息有何区别
  9. 【转】Java并发编程:如何创建线程?
  10. python结合pyvmomi 监控esxi的磁盘等信息