bnghtz

matek_hatvany_mod100.c

Nov 24th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. /*
  2.  * Mennyi 6789^8642 és 6789^8679 utolsó két számjegye?
  3.  * utolso 2 szamjegy --> mod 100
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. void keres(int x, int ad, int mod) {
  9.     int i, temp;
  10.    
  11.     // x^1:
  12.     temp = x % mod;
  13.     // x^2 .. ad
  14.     for (i = 2; i <= ad; i++) {
  15.         temp = (temp * x) % mod;
  16.     }
  17.     printf("%i.: %i\n", ad, temp);
  18. }
  19.  
  20. main()
  21. {
  22.     keres(6789, 8642, 100);
  23.     keres(6789, 8679, 100);
  24.  
  25.     return 0;
  26. }
  27.  
  28.  
  29. /*
  30. $ ./a.out
  31. 8642.: 21
  32. 8679.: 9
  33. */
Advertisement
Add Comment
Please, Sign In to add comment