hdu 2035 大数模

来源:互联网 发布:淘宝网红裤子店铺 编辑:程序博客网 时间:2024/05/22 01:51

这里需要注意的是,写移位或者位运算符的时候要加上括号,不然容易出错。

#include<stdio.h>#include<stdlib.h>#define n 1000int compute_a_b(int a,int b){    if(b==1) return a%n;    else if(b&1) return ((compute_a_b(a,b>>1)%n)*(compute_a_b(a,(b>>1)+1)%n))%n;    else if((b&1)==0) return ((compute_a_b(a,b>>1)%n)*(compute_a_b(a,b>>1)%n))%n;}int main(){    int a,b;    while(scanf("%d%d",&a,&b)&&a+b!=0){        printf("%d\n",compute_a_b(a,b));    }    return 0;}