华东交大友谊赛

       今天下午参加了华东交大邀请我们学校的acm友谊网络赛。题目还可以,但是上面支持的编译器是G++,GCC而不是VC的编译器。虽然差别看似不大,但是提交总出问题(如不能用float型数据,只能用double型的。做了一下午也就做出了三个(共十三个个),对比了一下别人的差距真实岗岗的,最高的做了10个真是牛人啊。这里给大家分享一个题,因为这个题想了好久都想不出来有什么好方法,希望各位高手指点:

Code:
  1. A^B   
  2.   
  3. Time Limit:1000MS  Memory Limit:65536K   
  4. Total Submit:208 Accepted:50    
  5.   
  6. Description    
  7.   
  8.   
  9. A^B means the Bth power of A, We know that 2^4=16 4^3=64, now your task is to calulate A^B ,but Zhou sir only wants to konw the last three digits of the answer .    
  10.   
  11.   
  12. Input    
  13.   
  14. The input will contain one or more lines. Each test case consists of two integers A and B(1<=A<=10000,B<=2000000000),The last test case is followed by two zeroes    
  15. Note that B is so large!    
  16.   
  17. Output    
  18.   
  19. print the last three digits of A^B    
  20.   
  21. Sample Input    
  22.   
  23.   
  24. 2 3   
  25. 12 6   
  26. 6789 10000   
  27. 6789 1234567890    
  28. 0 0   
  29.   
  30. Sample Output    
  31.   
  32.   
  33. 8   
  34. 984   
  35. 1   
  36. 401   
  37.   
  38.   
  39. Source    
  40.   
  41. zhousc   

我做了一下,一下是我的代码:

Code:
  1. #include <stdio.h>   
  2. #include <stdlib.h>   
  3.   
  4. int main()   
  5. {   
  6.     while(1)   
  7.     {   
  8.     int a,b,i,sum=1;   
  9.     scanf("%d %d",&a,&b);   
  10.     if(a==0&&b==0) break;     
  11.     a=a%1000;   
  12.     if(b%10000!=0)   
  13.     {   
  14.         b=b%10000;   
  15.     }   
  16.   
  17.     for(i=0;i<b;i++)   
  18.     {      
  19.         sum*=a;   
  20.         sum=sum%1000;   
  21.     }   
  22.     printf("%d/n",sum);   
  23.     }   
  24.     return 0;   
  25. }  

我的代码交上去后不能通过,原因是超时了。再结合题目推测超时是因为b的值太大了。那么现在的问题就是如何找到一个与b等价的b',这个b'不能太大而且效果要与b的效果一样。有哪位高手能够给个方法么,谢谢!

原题链接:http://acm.ecjtu.jx.cn:8080/JudgeOnline/showproblem?problem_id=1162

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值