Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <set>
  6. #include <map>
  7. #include <ctime>
  8. #include <cstdlib>
  9.  
  10. using namespace std;
  11.  
  12. const int MAXN = (int) 50 + 7;
  13.  
  14. typedef long long ll;
  15.  
  16. int a[11];
  17.  
  18. int n, r;
  19.  
  20. int get_s() {
  21. int q = 0;
  22. for (int i = 0; i < n - 1; i++)
  23. q += a[i] * a[i + 1];
  24. return q % r;
  25. }
  26.  
  27. bool is_good(int x) {
  28. if (x == 0)
  29. return true;
  30. int cnt = 0;
  31. for (int i = 1; i * i <= x; i++) {
  32. if (x % i == 0) {
  33. if (i * i != x)
  34. cnt++;
  35. cnt++;
  36. }
  37. }
  38. return (cnt % 3 == 0);
  39. }
  40.  
  41. int main() {
  42. freopen("beautiful.in", "r", stdin);
  43. freopen("beautiful.out", "w", stdout);
  44. cin >> n >> r;
  45. for (int i = 0; i < n; i++)
  46. a[i] = i + 1;
  47. int ans = 0;
  48. do {
  49. ans += is_good(get_s());
  50. } while (next_permutation(a, a + n));
  51. cout << ans;
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement