253号错误是怎么回事?
pascal吧
全部回复
仅看楼主
level 11
noip质因数的题目一运行就这样子
Pascal说是253号错误,但是我找不到253号错误。貌似是运行时异常退出。
这是什么情况?
2015年06月06日 10点06分 1
level 11
题目是这样的
描述
已知正整数n是两个不同的质数的乘积,试求出较大的那个质数。
输入格式
输入只有一行,包含一个正整数n。
输出格式
输出只有一行,包含一个正整数p,即较大的那个质数。
对于60%的数据,6 ≤ n ≤ 1000。 对于100%的数据,6 ≤ n ≤ 2 * 10^9。
程序是这样的
var i,j,n:int64;
b:array[1..1000000] of boolean;
begin
assign(input,'t1773.in');reset(input);
readln(n);
fillchar(b,sizeof(b),true);
i:=2;
while i<=n do
begin
j:=2;
while j<=n div i do
begin
b[i*j]:=false;
j:=j+1;
end;
i:=i+1;
end;
i:=1;
while i<=n do
begin
if (b[i]=true)and(n mod i=0)and(b[n div i]=true) then
begin
writeln(n div i);
break;
end;
end;
end.
一开始开始数据用的是长整型,用for循环来做,之后改成了int64,用while循环。都不行,会出现一样的情况。
2015年06月06日 10点06分 2
level 10
可能是读取文件时读的顺序不对,检查一下文件类型和里面的东东
2015年06月06日 11点06分 3
读取文件检查过了,没有问题,即使去掉了问件输入输出也会有这个问题
2015年06月06日 12点06分
level 11
话说这种问题是不是去noip吧问更快解决
2015年06月06日 12点06分 4
level 10
你为什么数组后缀要设置那么大啊?
2015年06月06日 13点06分 5
题目中N的范围是6至20亿,20亿开个方取个整大概就是10万了
2015年06月06日 14点06分
然后我又脑残开大了些
2015年06月06日 14点06分
现在改了一下,问题小一些了,但是还是不知道问题出在哪里
2015年06月06日 14点06分
level 11
现在把程序改了一下,变成错误216了(存取非法)。是什么问题呢?
var i,j,n:longint;
b:array[1..100000] of boolean;
begin
readln(n);
fillchar(b,sizeof(b),true);
for i:=2 to trunc(sqrt(n)) do
if b[i] then
for j:=2 to trunc(sqrt(n)) div i do b[i*j]:=false;
for i:=2 to trunc(sqrt(n)) do
if (b[i]=true)and(n mod i=0)and(b[n div i]=true) then
begin
writeln(n div i);
break;
end;
end.
2015年06月06日 14点06分 6
这个真看不懂错在哪。。
2015年06月07日 23点06分
level 11
顶顶
2015年06月07日 10点06分 7
顶一顶,没人鸟我吗?
2015年06月07日 14点06分
level 11
虽然我也不是很清楚,但我告诉你文件夹和文件名除了字母下划线最好连空格也不要有,最好不要有中文
2015年06月07日 23点06分 8
不建议把程序拖到其他文件夹里,就在FPC/2.4.0/的那个文件夹里编(比较混乱的话浏览时按修改时间排序就行)。在其他文件夹编有一些不是很方便的地方
2015年06月07日 23点06分
回复
���ƻ�֮��
: 好吧,到时候我改改看看
2015年06月09日 15点06分
level 8
我来一个:
var
a,n:longint;
begin
readln(n);
for a:=2 to sqrt(n) do
if n mod a =0 then
break;
writeln(n div a);
end.
原理很简单,质数的因数只有1和它本身。
2015年06月09日 02点06分 9
望采纳!
2015年06月09日 02点06分
@1783952099 不行哦,这种做法比较慢,每枚举一个数都要判断一次是很耗时的
2015年06月09日 15点06分
1