caioj 1161 尤拉函式3:可見點數
阿新 • • 發佈:2018-12-10
(x, y)被看到僅當x與y互質
由此聯想到尤拉函式
x=y是1個點,然後把正方形分成兩半,一邊是φ(n)
所以答案是2*φ(n)+1
#include<cstdio> #include<cctype> #define REP(i, a, b) for(int i = (a); i < (b); i++) #define _for(i, a, b) for(int i = (a); i <= (b); i++) using namespace std; typedef long long ll; const int MAXN = 1123; ll euler[MAXN]; void get_euler() { _for(i, 1, MAXN) euler[i] = i; _for(i, 2, MAXN) { if(euler[i] == i) for(int j = i; j <= MAXN; j += i) euler[j] = euler[j] / i * (i - 1); euler[i] += euler[i-1]; } } void read(ll& x) { int f = 1; x = 0; char ch = getchar(); while(!isdigit(ch)) { if(ch == '-1') f = -1; ch = getchar(); } while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } x *= f; } int main() { get_euler(); ll n; read(n); _for(i, 1, n) { ll x; read(x); printf("%d %lld %lld\n", i, x, 2 * euler[x] + 1); } return 0; }