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. 【转载】Android 开发 命名规范

    原文地址:http://www.cnblogs.com/ycxyyzw/p/4103284.html 标识符命名法标识符命名法最要有四种: 1 驼峰(Camel)命名法:又称小驼峰命名法,除首单词外, ...

  2. MS MDS系列之初始MS Master Data Service(微软主数据服务)

    背景介绍: 主数据服务(Master Data Services)是微软平台支持的主数据管理(MDM)平台.类似MDS这样的系统,如果后续维护得当,会给企业提供一个强大的中心数据库系统,来防止企业数据 ...

  3. 2017年7月Web服务器调查报告

    在2017年7月的调查中,我们收到了来自1,767,964,429个网站和6,593,508个面向web的计算机的反馈.这是一个小小的进步,网站的数量增加了100万个(+0.06%),面向web的计算 ...

  4. 【SignalR学习系列】2. 第一个SignalR程序

    新建项目 1.使用VisualStudio 2015 新建一个Web项目 2.选择空模板 3.添加一个新的SignalR Hub Class (v2)类文件,并修改类名为ChatHub 4.修改Cha ...

  5. 【TRICK】解决锚点定位向下浮动Xpx问题

    1. 问题描述 页面滚动后,菜单栏会固定在页头,当锚点定位时,菜单会遮盖部分定位后的内容,所以需要在锚点定位后自动向下漂移Xpx. 2. 解决办法 a. 利用空div 占位,如下: <a hre ...

  6. jdk 环境变量配置方法总结

    全部修改在用户变量/系统变量 系统变量→新建 JAVA_HOME 变量 .变量值填写jdk的安装目录(本人是 D:\java\Java\jdk1.8.0_72) 系统变量→寻找 Path 变量→编辑在 ...

  7. ES6学习目录

    前面的话 ES6是JavaScript语言的下一代标准,已经在 2015 年 6 月正式发布.它的目标,是使得 JavaScript 语言可以用来编写复杂的大型应用程序,成为企业级开发语言 为什么要学 ...

  8. 5. Leetcode 448. Find All Numbers Disappeared in an Array

    Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...

  9. Linux入门基础知识

    注:内容系兄弟连Linux教程(百度传课:史上最牛的Linux视频教程)的学习笔记. Linux入门基础知识 1. Unix和Linux发展历史 二者就像父子关系,当然Unix是老爹.1965年,MI ...

  10. InputStreamReader读取文件出现乱码

    当你读取一个文本文件时,如果是在电脑记事本上面写的,然后保存.使用InputStreamReader读取出来,并且是按照他的编码格式读取出来,发现还是存在乱码,比如文本内容是“你好”,读出来显示是“? ...