zoukankan      html  css  js  c++  java
  • XidianOJ 1026 修理OJ

    题目描述

    Boooooom!XDOJ坏掉了!经分析,XDOJ坏掉和一个表达式runid mod oj_tot有关(mod表示取余数,例如10 mod 3=1,5 mod 1=0)。

    由于runid可能很大,它被表示成ab的形式。

    由于xry111前一天CF打得太晚,现在他完全傻逼了,算不出这个表达式的值。请你写一个程序计算这个值。

    数据范围:1<=a, b, oj_tot<=1000

    输入

    多组数据(不超过1000组),每组数据1行,包括3个整数a、b、oj_tot。

    输出

    输出一行,包含一个整数ab mod oj_tot。

    --正文

    典型的快速幂

    #include <stdio.h>
    #include <math.h>
    
    int Cal(int a,int b,int n){
        int d = 1;
        int bin[20] = {0};
        int total = 0;
        while (b > 0){
            bin[total] = b % 2;
            b = b / 2;
            total ++;
        } 
        int k = total-1; 
        while (k >= 0){
            d = (d*d) % n;
            //printf("%d %d %d
    ",a,b,d);
            if (bin[k] == 1){
                d = (d*a) % n; 
            } 
            k --;
        }
        
        return d;
    }
    
    int main(){
        int a,b,oj_tot;
        while (scanf("%d %d %d",&a,&b,&oj_tot)!=EOF){
            printf("%d
    ",Cal(a,b,oj_tot));
        }
        
        return 0;
    }
  • 相关阅读:
    iSCSI又称为IPSAN
    文档类型定义DTD
    HDU 2971 Tower
    HDU 1588 Gauss Fibonacci
    URAL 1005 Stone Pile
    URAL 1003 Parity
    URAL 1002 Phone Numbers
    URAL 1007 Code Words
    HDU 3306 Another kind of Fibonacci
    FZU 1683 纪念SlingShot
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6063565.html
Copyright © 2011-2022 走看看