ZOJ 3785 What day is that day?(数论:费马小定理)
What day is that day?
Time Limit: 2 Seconds Memory Limit: 65536 KB
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.
分析:运用费马小定理,简化运算并求出循环节
1^1 2^2 3^3 4^4 5^5 6^6 7^7
8^8 9^9 10^10 11^11 12^12 13^13 14^14
15^15 16^16 17^17 18^18 19^19 20^20 21^21
22^22 23^23 24^24 25^25 26^26 27^27 28^28
29^29 30^30 31^31 32^32 33^33 34^34 35^35
36^36 37^37 38^38 39^39 40^40 41^41 42^42
43^43 44^44 45^45 46^46 47^47 48^48 49^49
转化后-->>
1^1 2^2 3^3 4^4 5^5 6^6 0
1^2 2^3 3^4 4^5 5^6 6^1 0
1^3 2^4 3^5 4^6 5^1 6^2 0
1^4 2^5 3^6 4^1 5^2 6^3 0
1^5 2^6 3^1 4^2 5^3 6^4 0
1^6 2^1 3^2 4^3 5^4 6^5 0
1^1 2^2 3^3 4^4 5^5 6^6 0
#include<iostream>
#include<math.h>
#define ll long long
using namespace std;
int s[50];
void chose(ll x){
switch(x){
case 0:printf("Sunday\n");break;
case 1:printf("Monday\n");break;
case 2:printf("Tuesday\n");break;
case 3:printf("Wednesday\n");break;
case 4:printf("Thursday\n");break;
case 5:printf("Friday\n");break;
case 6:printf("Saturday\n");break;
}
}
int main()
{
int T;
ll n;
for(int i=1;i<=42;i++){
int a,p,sum=1;
p=(i%6)?i%6:6;
//为6的倍数情况下保留一个六
a=i%7;
for(int j=1;j<=p;j++)
sum=(sum*a)%7;
s[i]=(s[i-1]+sum)%7;
}
scanf("%d", &T);
while(T--){
scanf("%lld", &n);
ll ans=(n/42%7*s[42]%7+s[n%42])%7;
ans=(ans+6)%7;
chose(ans);
}
return 0;
}
ZOJ 3785 What day is that day?(数论:费马小定理)的更多相关文章
- 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum
Sum Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...
- Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )
题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
- poj 1845 【数论:逆元,二分(乘法),拓展欧几里得,费马小定理】
POJ 1845 题意不说了,网上一大堆.此题做了一天,必须要整理一下了. 刚开始用费马小定理做,WA.(poj敢说我代码WA???)(以下代码其实都不严谨,按照数据要求A是可以等于0的,那么结果自然 ...
- 数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)
Ignatius's puzzle Problem Description Ignatius is poor at math,he falls across a puzzle problem,so h ...
- 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}
题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...
- ZOJ 3785 What day is that day?(今天是星期几?)
Description 题目描述 It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? 今天是星期六,11 + ...
- 数论入门——斐蜀定理与拓展欧几里得算法
斐蜀定理 内容 斐蜀定理又叫贝祖定理,它的内容是这样的: 若$a,bin N$,那么对于任意x,y,方程$ax+by=gcd(a,b)*k(kin N)$一定有解,且一定有一组解使$ax+by=gcd ...
- ZOJ 3785:What day is that day?(数论)
What day is that day? Time Limit: 2 Seconds Memory Limit: 65536 KB It's Saturday today, what day is ...
随机推荐
- 安装mysql8.0.12以及修改密码和Navicat的连接
mysql8.0+与安装其他版本不同一.安装mysql8.0.121.到官网https://www.mysql.com/ 下载mysql-8.0.12-winx64.zip(不要.mis),直接解压 ...
- eclipse常用快捷键和插件
1.快捷键 找实现类 ctrl +T 抽取為方法:alt+shift+M (Method) 方法返回值 ctrl+1 enter 2.在做Java项目的时候如何把第三方的jar包一起打包成jar文件 ...
- 【转】Python模块学习 - fnmatch & glob
[转]Python模块学习 - fnmatch & glob 介绍 fnmatch 和 glob 模块都是用来做字符串匹配文件名的标准库. fnmatch模块 大部分情况下使用字符串匹配查找特 ...
- js变量的解构赋值
今天在学习时看到几段代码,让我感叹JS的灵活,特此一记: let stateObj = {a:1,b:3}; let newObj = {b:13,c:4} ; stateObj = {...stat ...
- Java的static类
首先Java的static类只能是静态内部类.如果在外部类声明为static,程序会编译通不过. 其次,主要了解下static内部类与普通内部类的区别是什么,以及static内部类的作用是什么,详见下 ...
- python下载夏目友人帳
python下载夏目友人帐 一般情况下我们使用爬虫更多的应该是爬数据或者图片吧,今天在这里和大家分享一下关于使用爬虫技术来进行视频下载的方法,不仅可以方便的下载一些体积小的视频,针对大容量的视频下载同 ...
- 设计模式C++学习笔记之三(Singleton单例模式)
单例模式看起来也蛮简单的,就是在系统中只允许产生这个类的一个实例,既然这么简单,就直接贴代码了.更详细的内容及说明可以参考原作者博客:cbf4life.cnblogs.com. 3.1.解释 main ...
- $Django 图片验证刷新 上传头像
1.图片验证刷新 $('img').click(function () { $('img')[0].src+='?' }) 2.上传头像 1.模板 <div class="form-g ...
- 神经网络rbf
clc; clear; close all; ld=400; %定义学习样本的数量 x=rand(2,ld); %得到一个2 * 400的一个矩阵,每个元素在0-1之间 x=(x-0.5)*1.5*2 ...
- Day8--------------源码安装
yun install python 在yum源中 wget 地址 下载 下载---------->解包-------->运行config脚本添加编译参数--------->编译(g ...