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

注意1的情况,顺便粘一发代码

Posted by yousiki at 2016-07-24 11:03:48 on Problem 3048
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 20005;
int n, ans = 1, prime = 1;
int pre[N], pri[N], tot = 0;
signed main(void) {
	memset(pre, 0, sizeof(pre));
	for (int i = 2; i < N; i++) {
		if (pre[i] == 0)pri[++tot] = i;
		for (int j = 1; j <= tot&&i*pri[j] < N; j++) {
			pre[i*pri[j]] = pri[j];
			if (i%pri[j] == 0)break;
		}
	}
	scanf_s("%d", &n);
	for (int i = 1, x; i <= n; i++) {
		scanf_s("%d", &x);
		for(int j=lower_bound(pri+1,pri+1+tot,x)-pri;j;j--)
			if (pri[j] <= x&&x%pri[j] == 0) {
				if (prime < pri[j])prime = pri[j], ans = x;
				break;
			}
	}
	printf("%d\n", ans);
}

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