fork download
  1. #include <stdio.h>
  2.  
  3. int power(int x, int y){
  4. //x**y
  5. if(y==0) return 1;
  6. else return power(x,y-1)*x;
  7. }
  8.  
  9. int fastpower(int x, int y){
  10. if (y==0) return 1;
  11. else if((y%2)==0) return fastpower(x*x,y/2);
  12. else return x* fastpower(x*x,(y)/2);
  13.  
  14. }
  15.  
  16. int main(void){
  17. int x;
  18. int y;
  19. scanf("%d %d",&x,&y);
  20. printf("%d",power(x,y));
  21. printf(" %d",fastpower(x,y));
  22.  
  23. }
Success #stdin #stdout 0.01s 5312KB
stdin
5 2
stdout
25 25