zoj3785 What day is that day?
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 + ... + NN 天后是星期几?
思路:因为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?的更多相关文章
- 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 ...
随机推荐
- Java 9 揭秘(16. 虚拟机栈遍历)
Tips 做一个终身学习的人. 在本章中,主要介绍以下内容: 什么是虚拟机栈(JVM Stack)和栈帧(Stack Frame) 如何在JDK 9之前遍历一个线程的栈 在JDK 9中如何使用Stac ...
- Python简易爬虫爬取百度贴吧图片
通过python 来实现这样一个简单的爬虫功能,把我们想要的图片爬取到本地.(Python版本为3.6.0) 一.获取整个页面数据 def getHtml(url): page=urllib.requ ...
- hadoop入门,跑出第一个WordCount
1.环境准备 下载:http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz 解压:解压后,修改et ...
- 微信小程序开发
一.基本的准备工作 1.工具安装 工具是有微信官方提供. 2.下载地址: windows32位:https://servicewechat.com/wxa-dev-logic/download_red ...
- Java中基本数据类型和包装类
参考:深入剖析Java中的装箱和拆箱; Java中基本数据类型和包装类互转中 缓冲机制的使用; java学习笔记:装箱和拆箱,包装器和缓冲池 Java 各 类型数据在内存中分配情况详解 一 java内 ...
- 在html中使用javascript
使用script元素,script6个元素 1.async:应该立即下载 2.charset:通过src属性指定代码的字符集 3.defer:表示脚本可以延迟到文档完全解析和显示后运行 4.langu ...
- jQuery 去空
//去左右空格; function trim(s){ return s.replace(/(^\s*)|(\s*$)/g, ""); } //去掉字符串中所有空格(包括中间 ...
- mybatis 详解(四)------properties以及别名定义
上一篇博客我们介绍了mybatis的增删改查入门实例,我们发现在 mybatis-configuration.xml 的配置文件中,对数据库的配置都是硬编码在这个xml文件中,如下图,那么我们如何改进 ...
- 页面发送请求到后台报错“Empty or invalid anti forgery header token.”问题解决
在页面向后台发送请求时,报如上图的错误的解决办法: 在WebModule.cs类中的PreInitialize方法中加 Configuration.Modules.AbpWeb().AntiForge ...
- 给View添加手势,防止点击View上其他视图触发点击效果
在开发过程中,我们可能会遇到这个问题. 当我们给一个view添加了手势,但是我们又不想点击view上面的视图也触发手势.如下图: 我们在红色view上添加了手势,但是又不想点击黄色view也触发.其实 ...