Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不知道为啥用欧拉函数。斜率判重土方法胡搞过了。

Posted by Liuzhaoliang at 2014-08-17 13:14:25 on Problem 3090
const int MAXN = 1001;
int gcd(int a, int b) {
    if (!b) return a;
    return gcd(b, a % b);
}
int visited[MAXN][MAXN];
int answer[1001];
int cnt = 0;
void add_point(int i,int j){
    int g = gcd(i,j);
    if(!visited[i/g][j/g]){
        cnt++;
        visited[i/g][j/g] = 1;
    }
}
int main() {
    for (int k = 1; k <= 1000; k++) {
        for(int i=0;i<=k;i++) add_point(i,k);
        for(int i=0;i<k;i++) add_point(k,i);
        answer[k] = cnt;
    }
    int C, N;
    scanf("%d", &C);
    for (int i = 0; i < C; i++) {
        scanf("%d", &N);
        printf("%d %d %d\n", i + 1, N, answer[N]);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator