zoukankan      html  css  js  c++  java
  • All X(思维)

    All X

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 813    Accepted Submission(s): 392

    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”。
     
    Source
     

    题解:本来想着逆元的,谁知道不用逆元就行,x*(10^m - 1)/9 %k;

    由于10^m - 1一定可以整除9;只需要对9*k取模,再除以9;就得到了(10^m - 1)/9 %k,乘以x在%k就好了;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef __int64 LL;
    template<typename T>
    LL quick_mul(LL a, T n, T k){
        LL ans = 1;
        while(n){
            if(n & 1)
                ans = ans * a % k;
            n >>= 1;
            a = a * a % k;
        }
        return ans;
    }
    int main(){
        int T, kase = 0;
        LL x,m,k,c;
        scanf("%d", &T);
        while(T--){
            scanf("%I64d%I64d%I64d%I64d", &x,&m,&k,&c);
            k *= 9;
            LL ans = ((quick_mul(10, m, k) - 1 + k)%k/9)*x%(k/9);
            printf("Case #%d:
    %s
    ", ++kase, ans == c?"Yes":"No");
        }
        return 0;
    }
  • 相关阅读:
    曾国藩谕纪泽纪鸿
    简单实现KeyChain实例
    UUID、UDID和KeyChain
    iOS沙盒目录结构解析 (转)
    BOOL布尔类型
    表达式
    赋值运算符
    变量
    常量
    GET请求和POST请求简单说明
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5517939.html
Copyright © 2011-2022 走看看