Home | Problems | Discuss | Login

  

超时怎么解决哦?

2656: A Simple Problem

0542011069 | 2007-04-20 20:55:47 | delete | edit
import java.util.*;
class Main{
public static void main(String arg[]){
System.out.println("enter a number that is between 0 and 1 billion");
int i,j=-1,l,s=1;
long M,N;
do{Scanner Q=new Scanner(System.in);
N=Q.nextLong();}
while(N<1||N>1000000000);
if(N==1)System.out.println("2");
else{
int a[]=new int[10];
M=N;
if(N%2==0)j++;
while(N%2==0){a[j]=2;N/=2;}
for(i=3;N!=1;i+=2){
if(N%i==0)j++;
while(N%i==0){a[j]=i;
N/=i;}
}
for(l=0;l<=j;l++){s*=a[l];}
System.out.println(M/s+1);
}
}
}为什么memery那么大,我错在那里了,谢谢请帮帮忙! 
windy7926778 | 2007-04-20 18:56:34 | delete | edit
./Main.java:2: 类重复: mod
class mod{
^
Launcher.java:8: 无法访问 Main
错误的类文件: ./Main.java
文件不包含类 Main
请删除该文件或确保该文件位于正确的类路径子目录中。
			Main.main(args);
                        ^
2 错误



这是你的错误信息 
windy7926778 | 2007-04-20 18:56:00 | delete | edit
0542011069 
你的算法是正确的,java我不熟悉,但是CE,SOJ都有提示的 
0542011069 | 2007-04-20 18:54:20 | delete | edit
可以试下这个算法:先将N标准分解,再将每个因子取出一个,然后乘起来得到N1,N/N1+1就可得到答案,但我有个问题他说Compilation Error 是怎么回事,对文件名什么特别要求吗?我是用java的 
windy7926778 | 2007-04-18 19:57:05 | delete | edit
里面直接用筛法一样能做,不需要打表 
int | 2007-04-18 19:03:06 | delete | edit
有没有不是用素数表过的啊
 
windy7926778 | 2007-04-17 15:47:04 | delete | edit
对头 
wqb0039 | 2007-04-17 13:33:26 | delete | edit
多数是算法不对... 
echome | 2007-04-16 23:54:28 | delete | edit
 

Please login to reply.