zoukankan      html  css  js  c++  java
  • All X_数的快速幂

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


    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<iostream>
    #include<stdio.h>
    #include<string.h>
    using namespace std;
    long long int x,m,k,c;
    long long int pow(long long int a,long long int n,long long int mod)//快速幂
    {
        long long int ans=1;
        while(n)
        {
            if(n&1) ans=ans*a%mod;
            n>>=1;
            a=a*a%mod;
        }
        return ans;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        int cas=1;
        while(t--)
        {
            printf("Case #%d:
    ",cas++);
            scanf("%lld%lld%lld%lld",&x,&m,&k,&c);
            int p=pow(10,m,k);
            if(x*p%k==(9*c+x)%k) printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    文件处理--文件操作
    三元运算
    alex 推荐的书
    python字符串、列表和字典的说明
    运算符
    while else语句
    格式化输出
    数据类型-元组
    数据类型-集合
    字符串
  • 原文地址:https://www.cnblogs.com/iwantstrong/p/5976154.html
Copyright © 2011-2022 走看看