链接:https://ac.nowcoder.com/acm/contest/3674/E
来源:牛客网
题目描述
LYX is the most handsome boy in HNU who likes math very much. One day his girlfriend JY asked LYX a simple problem: “Today is Sunday , what day of week will it be after 400^600 days, and what about 120^714?” LYX is very smart and answered: It will be Monday and Monday.
Now LYX abstracts this problem as follows:
‘a’ denote the day of week today(‘a’ belong to {Mon, Tue, Wed, Thu, Fri, Sat, Sun}), what is the date after NM(1<=N<1010000,6<=M<10000) days ? Where M is exactly divided by 6.
输入描述:
There is 1 line, 1 string, 2 integers,
there are a, N and M, separated by a space.
输出描述:
Output a string(Mon, Tue, Wed, Thu, Fri, Sat, Sun), the day of the week.
示例1
输入
Sun 2 12
输出
Mon
说明
The day(Sunday) after 212(4,096) days will be Monday.
示例2
输入
Wed 7 6
输出
Wed
说明
The day(Wednesday) after 76(117,649) days will be Wednesday.
示例3
输入
Thu 1 6
输出
Fri
说明
The day(Thursday) after 16(1) days will be Friday.
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
#include <iomanip>
#include<cstring>
using namespace std;
typedef long long ll;
int mod = 7;
string week[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
ll qpow(ll a, ll b) {
ll res = 1;
a = a % mod;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main()
{
string day;
cin>>day;
string N;
ll M;
cin>>N>>M;
int a=(N[0]-48)%mod;
for(unsigned long i=1;i<N.size();i++)
{
a=(a*10+(N[i]-48))%mod;
}
// cout<<a;
ll temp = qpow(a, M);
for(int i =0;i<7;i++)
{
if(day == week[i])
{
cout<<week[(i+temp)%7];
break;
}
}
}