Advertisement
a53

SuperPerfecte

a53
Oct 8th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. ifstream f("superperfecte.in");
  5. ofstream g("superperfecte.out");
  6. long long n , i , m , k , x , y , z , t , x1 , y1 , z1 , t1 , sol , c [ 101 ] , d ;
  7.  
  8. int main()
  9. {
  10. d = 555557 ;
  11. f >> n ;
  12. if ( n == 1 ) g << 4 ;
  13. if ( n == 2 ) g << 3 ;
  14. if ( n == 3 ) g << 12 ;
  15. if ( n >= 4 )
  16. {
  17. m = n - 3 ;
  18. k = 0 ;
  19. while ( m != 0)
  20. {
  21. k++ ;
  22. c [ k ] = m % 2 ;
  23. m = m / 2 ;
  24. }
  25. x = 1 ; y = 0 ;
  26. z = 0 ; t = 1 ;
  27. for ( i = k ; i >= 1 ; i-- )
  28. if ( c [ i ] == 1 )
  29. {
  30. x1 = ( x * x + y * z + x * y + y * t ) % d ;
  31. y1 = ( 3 * x * x + 3 * y * z ) % d ;
  32. z1 = ( x * z + z * t + y * z + t * t ) % d ;
  33. t1 = ( 3 * x * z + 3 * z * t ) % d ;
  34. x = x1 ; y = y1 ; z = z1 ; t = t1 ;
  35. }
  36. else
  37. {
  38. x1 = ( x * x + y * z ) % d ;
  39. y1 = ( x * y + y * t ) % d ;
  40. z1 = ( x * z + z * t ) % d ;
  41. t1 = ( y * z + t * t ) % d ;
  42. x = x1 ; y = y1 ; z = z1 ; t = t1 ;
  43. }
  44. sol = ( 3 * x + 3 * y + 9 * z + 9 * t ) % d ;
  45. g << sol ;
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement