带模除法
2015-07-19 13:24
204 查看
What day is that day?
It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days?
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).
For each test case, output one string indicating the day of week.
21
2
SundayThursday
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
可以打表,四十个一循环。
然而我一开始没看出来有规律的,就正常做了
首先可以把每一个幂的底数都mod 7
这样就可以分成七组,
1^1,1^8,1^15.....
2^2,2^9,2^16.....
3^n,3^10,3^17......
////
这样第七组就可以省略了
第一组也都是1,
每一组都可以用等比数列来求和
求和之后会有一个表达式
然而有分母,这样我们每一次都取模的话就不会了
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
212
Sample Output
SundayThursday
Hint
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.可以打表,四十个一循环。
然而我一开始没看出来有规律的,就正常做了
首先可以把每一个幂的底数都mod 7
这样就可以分成七组,
1^1,1^8,1^15.....
2^2,2^9,2^16.....
3^n,3^10,3^17......
////
这样第七组就可以省略了
第一组也都是1,
每一组都可以用等比数列来求和
求和之后会有一个表达式
然而有分母,这样我们每一次都取模的话就不会了
相关文章推荐
- 九十个少为人知的小知识
- 9条PHP编程小知识及易犯的小错误
- C#中关于可空类型的小知识
- JSP小知识简单介绍
- Javascript中this关键字的一些小知识
- JavaScript编程中容易出BUG的几点小知识
- 常用小知识
- 笔记本电脑CPU正常温度是多少?怎样控制与防范?
- java小精华
- 【小常识】Appdata\Local Roaming LocalLow文件夹简介
- 【小常识】Appdata\Local Roaming LocalLow文件夹简介
- Unity中常见错误/常见小知识(动态补充)
- android小知识
- 小知识
- oracle数据库常识
- linux 小知识系列
- 一路走来!!
- 一些小命令
- 时间格式化