Description
You may not know this but it's a fact that Xinghai Square is Asia's largest city square. It is located in Dalian and, of course, a landmark of the city. It's an ideal place for outing any time of the year. And now:
There are
children from a nearby primary school flying kites with a teacher. When they have a rest at noon, part of them (maybe none) sit around the circle flower beds. The angle between any two of them relative to the center of the circle is always a multiple of
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4cfdb42d2fb296fa59fecc77aa8d3f40.png)
but always not
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4cfdb42d2fb296fa59fecc77aa8d3f40.png)
.
Now, the teacher raises a question: How many different ways there are to arrange students sitting around the flower beds according to the rule stated above. To simplify the problem, every student is seen as the same. And to make the answer looks not so great, the teacher adds another specification: two ways are considered the same if they coincide after rotating.
There are
![](https://i-blog.csdnimg.cn/blog_migrate/6392eb09bd980819d2aae2f522e4af00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4cfdb42d2fb296fa59fecc77aa8d3f40.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6392eb09bd980819d2aae2f522e4af00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4cfdb42d2fb296fa59fecc77aa8d3f40.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6392eb09bd980819d2aae2f522e4af00.png)
Now, the teacher raises a question: How many different ways there are to arrange students sitting around the flower beds according to the rule stated above. To simplify the problem, every student is seen as the same. And to make the answer looks not so great, the teacher adds another specification: two ways are considered the same if they coincide after rotating.
Input
There are
tests (
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b503db96fe85a552479ddbd4b574df16.png)
). Each test contains one integer
.
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6392eb09bd980819d2aae2f522e4af00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25da3021e94f663f575c49ea7a9a9fc1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
. Process till the end of input.
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b503db96fe85a552479ddbd4b574df16.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6392eb09bd980819d2aae2f522e4af00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6392eb09bd980819d2aae2f522e4af00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25da3021e94f663f575c49ea7a9a9fc1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
Output
For each test, output the answer mod 1000000007 (
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e55d414846558ea8e1501b5ff737c782.png)
) in one line.
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e55d414846558ea8e1501b5ff737c782.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9abbdf185d2bae2b94276915537fb23.png)
Sample Input
4 7 10
Sample Output
3 515
数论水平尚低,搞不来推导。
![]()
搞到公式的话就简单了,直接照着打即可。
注意需要特判1的情况。
#include<set> #include<map> #include<ctime> #include<cmath> #include<stack> #include<queue> #include<bitset> #include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define loop(i,j,k) for (int i = j;i != -1; i = k[i]) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r #define ff first #define ss second #define mp(i,j) make_pair(i,j) #define pb push_back #define pii pair<int,LL> #define inone(x) scanf("%d", &x); #define intwo(x,y) scanf("%d%d", &x, &y); using namespace std; typedef unsigned long long LL; const int low(int x) { return x&-x; } const double eps = 1e-4; const int INF = 0x7FFFFFFF; const int mod = 1e9 + 7; const int N = 1e5 + 10; int n; int a[2], b[2][2], c[2][2]; int phi(int x) { int res = 1; for (int i = 2; i*i <= x; i++) { if (x % i) continue; res *= i - 1; x /= i; while (x%i == 0) res *= i, x /= i; } return res * max(x - 1, 1); } int exgcd(int a, int b, int &x, int &y) { if (!b) { x = 1; y = 0; return a; } int g = exgcd(b, a % b, x, y); int z = x - a / b * y; x = y; y = z; return g; } int get(int x) { if (x == 1) return 1; a[0] = 0; a[1] = 1; b[0][0] = b[0][1] = -1; b[1][0] = 1; b[1][1] = 2; for (--x; x; x >>= 1) { if (x & 1) { rep(i, 0, 1) { c[0][i] = 0; rep(j, 0, 1) c[0][i] = (1LL * a[j] * b[j][i] + c[0][i]) % mod; } rep(i, 0, 1) a[i] = c[0][i]; } rep(i, 0, 1) rep(j, 0, 1) { c[i][j] = 0; rep(k, 0, 1) c[i][j] = (1LL * b[i][k] * b[k][j] + c[i][j]) % mod; } rep(i, 0, 1) rep(j, 0, 1) b[i][j] = c[i][j]; } return ((a[0] + a[1]) % mod + mod) % mod; } int main() { while (scanf("%d", &n) != EOF) { if (n == 1) { printf("2\n"); continue; } int x, y; exgcd(n, mod, x, y); LL ans = 0; for (int i = 1; i*i <= n; i++) { if (n % i) continue; ans += 1LL * phi(n / i) * get(i) % mod; if (i*i == n) continue; ans += 1LL * phi(i) * get(n / i) % mod; } printf("%lld\n", ans % mod * (x % mod + mod) % mod); } return 0; }