zoukankan      html  css  js  c++  java
  • hdu-5690 All X(快速幂+乘法逆元)

    题目链接:

    All X

    Time Limit: 2000/1000 MS (Java/Others)   

     Memory Limit: 65536/65536 K (Java/Others)


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

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

    1x9 

    1m10^10

    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
     
    题意:
     
     
    思路:
     
    m个x组成的数可以表示为x*(1+10+10^2+...+10^m-1)=x*(10^m-1)/9;
    即x*(10^m-1)/9%k==c?    x*(10^m-1)%(9*k)==9*c?
     
    AC代码:
     
     
    //#include <bits/stdc++.h>
    
    #include <iostream>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    //const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=1e5+25;
    LL x,m,k,c;
    LL mod;
    LL fastmod(LL x,LL y)
    {
        LL ans=1,base=x;
        while(y)
        {
            if(y&1)ans*=base,ans%=mod;
            base*=base;
            base%=mod;
            y=(y>>1);
        }
        return ans;
    }
    int main()
    {
         int t,cnt=1;
         scanf("%d",&t);
         while(t--)
         {
             printf("Case #%d:
    ",cnt++);
             scanf("%I64d%I64d%I64d%I64d",&x,&m,&k,&c);
                mod=9*k;
              LL fx=fastmod(10,m);
              LL ans=(fx*x%mod-x%mod)%mod;
              if(ans==9*c)printf("Yes
    ");
              else printf("No
    ");
         }
    
    
        return 0;
    }
     
  • 相关阅读:
    oracle Blob处理
    开机启动
    获取本机IP
    MSSQL通用分页过程
    转:Delphi2010小写金额转大写金额的源代码
    HWND Handle HModule区别
    常见问题
    Oracle ORA-01033: 错误解决办法
    lvs- lvs(DR模式)+keepalived
    lb-常用的负载均衡软件
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5515260.html
Copyright © 2011-2022 走看看