大数取模及快速幂

链接: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;
        }
    }

    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值