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.

题目大意:今天是星期六,输入n,问11 + 22 + 33 + ... + N天后是星期几?

思路:因为n是10亿,解法必定是数学方法或者找规律。注意到7是素数,所以可以使用费马小定理进行简化。即当p是素数是,a^(p-1) mod p=1,简化后发现每42个数就会出现一个循环,得数mod7=6。所以求解过程就是先求出n由几个42组成,对于42取余的剩下的部分就可以直接模拟做了。

 /*
* Author: Joshua
* Created Time: 2014/5/17 13:18:55
* File Name: j.cpp
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<ctime>
#include<utility>
#define M0(x) memset(x, 0, sizeof(x))
#define MP make_pair
#define Fi first
#define Se second
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define red(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define Inf 0x3fffffff
#define eps 1e-8
typedef long long LL;
using namespace std; string ans[]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"}; void solve()
{
int n,m,t=,temp;
scanf("%d",&n);
m=n/;
t=(t+m*)%;
for (int i=;i<=n%;i++)
{
temp=;
for (int j=;j<=i;j++)
temp=(temp*i)%;
t=(t+temp)%;
}
cout<<ans[t]<<endl;
}
int main()
{
int tt;
scanf("%d",&tt);
while (tt)
{
tt--;
solve();
}
return ;
}

许久没写了,代码太丑,大家凑合着看。。。

最新文章

  1. java web 学习 --第六天(Java三级考试)
  2. C# C/S WPF 远程操作服务器上面的文件
  3. 【SpringMVC】SpringMVC系列10之视图与视图解析器
  4. Android基础总结(7)——异步消息处理
  5. spring quartz 定时任务“Failed to load class &quot;org.slf4j.impl.StaticLoggerBinder”“Checking for available updated version of Quartz”
  6. flex超链接
  7. 利用transform制作幻灯片
  8. 关于sql多表去重问题
  9. java实现二维码的生成.
  10. MTK6261初始化待机流程
  11. MAVEN 加载公共包 commons
  12. php 数组模糊匹配
  13. 如何在servlet中获取spring创建的bean
  14. BZOJ3211: 花神游历各国(线段树)
  15. python&#39;s os.system&amp;os.spawn
  16. Asp.Net MVC Identity 2.2.1 使用技巧(七)
  17. [EffectiveC++]item02:尽量以const,enum,inline代替#define
  18. 2018-2019-2 网络对抗技术 20165322 Exp5 MSF基础应用
  19. Intelij Idea下的git使用
  20. avalon1.3的新特性预览

热门文章

  1. sqlserver提高篇
  2. 函数响应式编程及ReactiveObjC学习笔记 (三)
  3. C# 创建、部署和调用WebService的简单示例
  4. Maven安装及使用-超级图文初级篇-
  5. 关于EasyUI中DataGrid控件的一些使用方法总结
  6. [server]nginx 一系列命令
  7. storm从入门到放弃(三),放弃使用《StreamId》特性。
  8. java对excel表格的上传和下载处理
  9. OC-UICollectionView实现瀑布流
  10. hdu--1548--dfs--蜘蛛牌