HDU 5690 All X

Problem Description
F(x,m)  代表一个全是由数字 x 组成的 m 位数字。请计算,以下式子是否成立:

F(x,m) mod k  c
 

Input
第一行一个整数 T ,表示 T 组数据。
每组测试数据占一行,包含四个数字 x,m,k,c

1x9  

1m1010

0c<k10,000
 

Output
对于每组数据,输出两行:
第一行输出:"Case #i:"。 i 代表第 i 组测试数据。
第二行输出“Yes” 或者 “No”,代表四个数字,是否能够满足题目中给的公式。
 

Sample Input
  
  
3 1 3 5 2 1 3 5 1 3 5 99 69
 

Sample Output
  
  
Case #1: No Case #2: Yes Case #3: Yes
Hint
对于第一组测试数据:111 mod 5 = 1,公式不成立,所以答案是”No”,而第二组测试数据中满足如上公式,所以答案是 “Yes”。

解法很多,可以矩阵可以循环节,可以快速幂,随便搞。

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<bitset>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int T, cas = 0;
LL x, m, c, k, ans;

int get(LL x)
{
    int res = 1;
    for (int i = 10; x; x >>= 1)
    {
        if (x & 1) res = res*i % c;
        i = i*i%c;
    }
    return res;
}

int main()
{
    scanf("%d", &T);
    while (T--)
    {
        scanf("%I64d%I64d%I64d%I64d", &x, &m, &c, &k);
        ans = 0;
        for (LL i = 1, j = x, k = 1; m; i <<= 1)
        {
            if (m&i)
            {
                (ans += j*k%c) %= c;
                m ^= i; k = k*get(i) % c;
            }
            j = (j + j*get(i)) % c;
        }
        printf("Case #%d:\n%s\n", ++cas, ans == k ? "Yes" : "No");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值