Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- const int MAXN = (int) 50 + 7;
- typedef long long ll;
- int a[11];
- int n, r;
- int get_s() {
- int q = 0;
- for (int i = 0; i < n - 1; i++)
- q += a[i] * a[i + 1];
- return q % r;
- }
- bool is_good(int x) {
- if (x == 0)
- return true;
- int cnt = 0;
- for (int i = 1; i * i <= x; i++) {
- if (x % i == 0) {
- if (i * i != x)
- cnt++;
- cnt++;
- }
- }
- return (cnt % 3 == 0);
- }
- int main() {
- freopen("beautiful.in", "r", stdin);
- freopen("beautiful.out", "w", stdout);
- cin >> n >> r;
- for (int i = 0; i < n; i++)
- a[i] = i + 1;
- int ans = 0;
- do {
- ans += is_good(get_s());
- } while (next_permutation(a, a + n));
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement