Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1.  
  2.  
  3. using System;
  4. using System.IO;
  5. using System.Collections.Generic;
  6. using System.Globalization;
  7.  
  8. namespace ADS.Week8
  9. {
  10. public class HashTable
  11. {
  12. private int tableSize;
  13. private long[] table;
  14.  
  15. public HashTable(int size)
  16. {
  17. tableSize = size;
  18. table = new long[size];
  19. for (int i = 0; i < size; i++)
  20. table[i] = -1;
  21. }
  22.  
  23. public bool TryInsert(long key)
  24. {
  25. int hash = GetHash(key);
  26. int hash2 = GetHash2(key);
  27. while (table[hash] != -1 && table[hash] != key)
  28. {
  29. hash = (hash + hash2) % tableSize;
  30. hash2++;
  31. }
  32. if (table[hash] == key)
  33. return false;
  34. table[hash] = key;
  35. return true;
  36. }
  37.  
  38. private int GetHash(long key)
  39. {
  40. return Math.Abs(unchecked((int)((long)(key * 47))) ^ (int)((key * 31) >> 32)) % tableSize;
  41. }
  42. private int GetHash2(long key)
  43. {
  44. return Math.Abs(unchecked((int)((long)(key * 113))) ^ (int)((key * 97) >> 32)) % (tableSize - 1) + 1;
  45. }
  46. }
  47. public class Task3
  48. {
  49. public static void Main(string[] args)
  50. {
  51. using (StreamReader streamReader = new StreamReader("input.txt"))
  52. using (StreamWriter streamWriter = new StreamWriter("output.txt"))
  53. {
  54. string[] str = streamReader.ReadLine().Split(' ');
  55. int n = int.Parse(str[0]);
  56. long x = long.Parse(str[1]);
  57. int a = int.Parse(str[2]);
  58. long b = long.Parse(str[3]);
  59. str = streamReader.ReadLine().Split(' ');
  60. int ac = int.Parse(str[0]);
  61. long bc = long.Parse(str[1]);
  62. int ad = int.Parse(str[2]);
  63. long bd = long.Parse(str[3]);
  64.  
  65. HashTable hashTable = new HashTable(n * 2);
  66. for (int i = 0; i < n; i++)
  67. {
  68. if (hashTable.TryInsert(x))
  69. {
  70. a = (a + ad) % 1000;
  71. b = (b + bd) % 1000000000000000;
  72. }
  73. else
  74. {
  75. a = (a + ac) % 1000;
  76. b = (b + bc) % 1000000000000000;
  77. }
  78. x = (x * a + b) % 1000000000000000;
  79. }
  80. streamWriter.WriteLine("{0} {1} {2}", x, a, b);
  81. }
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement