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 ;
}

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

zoj3785 What day is that day?的更多相关文章

  1. ACM学习历程—ZOJ3785 What day is that day?(数论)

    Description It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are ...

随机推荐

  1. HDU 6040---Hints of sd0061(STL)

    题目链接 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired last year l ...

  2. 基于vue的颜色选择器color-picker

    项目中有用到颜色选择器的童鞋们可以看过来了 关于color-picker的jquery的插件是有蛮多,不过vue组件没有吧,反正我没有找到, 虽然element-ui里面有这个,但是你愿意为了一个小功 ...

  3. maven单元测试设置代理

    背景 环境需要设置代理才能够访问外部网络,如果只是运行java程序来访问网络,我们可以通过java -jar test.jar -DproxyHost=proxy_ip -DproxyPort=pro ...

  4. Angular4.0从入门到实战打造在线竞拍网站学习笔记之三--依赖注入

    Angular4.0基础知识之组件 Angular4.0基础知识之路由 依赖注入(Dependency Injection) 正常情况下,我们写的代码应该是这样子的: let product = ne ...

  5. python爬虫--自动获取seebug的poc

    简单的写了一个爬取www.seebug.org上poc的小玩意儿~ 首先我们进行一定的抓包分析 我们遇到的第一个问题就是seebug需要登录才能进行下载,这个很好处理,只需要抓取返回值200的页面,将 ...

  6. [补档][NOIP2015] 斗地主

    [NOIP2015] 斗地主 题目 传送门:http://cogs.pro/cogs/problem/problem.php?pid=2106 INPUT 第一行包含用空格隔开的2个正整数Tn,表示手 ...

  7. 常用颜色RGB、灰度值

    128/0/0       深红         255/0/0       红           255/0/255     粉红        255/153/204 玫瑰红       153 ...

  8. trie从入门到入殓

    trie是什么?1. 字典树 2.集合 (其实两个都对啊喂) 一颗普通的trie树一般类似于这样(图片来源于http://dongxicheng.org/structure/trietree/): 绿 ...

  9. Spyder项目创建,打开与使用

    1.Spyder项目的创建 新建一个Spyder项目需要点击Spyder上方标签栏中的Projects中的New Project 2.Spyder项目的打开 Spyder项目文件夹必须 存在.spyp ...

  10. 【CPP】数据和C

    %f是浮点型的占位符,%f.2表示显示到小数点后两位,.2称为修饰词 变量可以在程序执行过程中变化和指定,而常量不可以. [数据类型关键字]int long short unsigned char  ...