Advertisement
smatskevich

Seminar3

Jan 9th, 2022
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. typedef long long ll;
  7. typedef unsigned long long ull;
  8.  
  9. int main1() {
  10.   int n = 0;
  11.   cin >> n;
  12.  
  13.   int i = 2;
  14.   while (i <= sqrt(n) + 1) {
  15.     while (n % i == 0) {
  16.       n /= i;
  17.       cout << i << " ";
  18.     }
  19.     ++i;
  20.   }
  21.   if (n != 1) cout << n;
  22.   return 0;
  23. }
  24.  
  25. int main2() {
  26.   ull a = 0;
  27.   cin >> a;
  28.   int n = 0;
  29.   cin >> n;
  30.  
  31.   ull result = 1ull;
  32.   for (int i = 0; i < n; ++i) {
  33.     result = (result * a) % 1000000007;
  34.   }
  35.   cout << result << endl;
  36.  
  37.   double integral_part = 0;
  38.   double result2 = modf(pow(double(a), double(n)) / 1000000007., &integral_part);
  39.   result2 *= 1000000007.;
  40.   cout << ull(result2) << endl;
  41.   return 0;
  42. }
  43.  
  44. int main() {
  45.   int n = 0;
  46.   cin >> n;
  47.   vector<int> s(n);
  48.   for (int i = 0; i < n; ++i) cin >> s[i];
  49.   int a = 0, m = 0;
  50.   cin >> a >> m;
  51.  
  52.   ll hash = 0;
  53.   for (int value : s) {
  54.     hash = (hash * a + value) % m;
  55.   }
  56.   cout << hash << endl;
  57.  
  58.   return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement