P1463 [POI2002][HAOI2007]反素数

哎暴力算法打错了
错误是这样的:

for(int i=1; i<=rt_x; i++) {
	if(x % i == 0) sum++;
	if(x / i != i) sum++;
}

但实际上应该这样写:

for(int i=1; i<=rt_x; i++) {
	if(x % i == 0) {
		sum++;
		if(x / i != i) sum++;
	}
}

我没考虑到条件的嵌套
就这样吧,正解不会,打表过了
但是要注意只能不多不少地遍历表中元素,比如说表的大小为68,只能遍历0 ~ 67,若遍历到后面,当n很大的时候,就会取表的最后一个元素,若按我这种写法,他会取循环的最后一次,如果多遍历了,就会取到0

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
#define debug(x) cerr << #x << "=" << x << endl;
const int MAXN = 100000 + 10;
const int INF = 1 << 30;
typedef long long ll;
int n,m,now,ans;
int g[100] = {1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640,498960,554400,665280,720720,1081080,1441440,2162160,2882880,3603600,4324320,6486480,7207200,8648640,10810800,14414400,17297280,21621600,32432400,36756720,43243200,61261200,73513440,110270160,122522400,147026880,183783600,245044800,294053760,367567200,551350800,698377680,735134400,1102701600,1396755360};
int main() {
	scanf("%d", &n);
	for(int i=0; i<=67; i++) {
		if(g[i] <= n) ans = g[i];
		else break;
	}
	printf("%d\n", ans);
    return 0;
}
posted @ 2018-10-29 21:12  Zolrk  阅读(132)  评论(0编辑  收藏  举报