一个奇怪的问题
  • 板块题目总版
  • 楼主Novicelpx
  • 当前回复24
  • 已保存回复24
  • 发布时间2024/9/5 20:31
  • 上次更新2024/9/6 00:11:25
查看原帖
一个奇怪的问题
189912
Novicelpx楼主2024/9/5 20:31
#include<bits/stdc++.h>
using namespace std;
const int N=100000;
bool stan[N]={0};
int stand[N]={0};
void Output(){
	for(int i=1;i<=stand[0];i++)cout<<stand[i]<<' ';
	cout<<endl;
}
void Sieve(){
	cout<<stand[0]<<endl;//??????????????????????????
	stan[1]=1;
	stan[N]=1;
	cout<<stand[0]<<endl;//?????????????????????????
	for(int i=2;i<=100;i++){
		if(!stan[i]){
			//cout<<i<<' '<<stand[0]<<endl;
			stand[0]++;
			stand[stand[0]]=i;
			//cout<<stand[0]<<' '<<stand[stand[0]]<<endl;
			Output();
			for(int j=i*2;j<=N;j+=i)stan[j]=1;
		}
	}
}
int main(){
	cout<<stand[0]<<endl;//???????????????????????
	Sieve();
	//for(int i=1;i<=10;i++)cout<<stand[i]<<endl;
	int n;
	cin>>n;
	for(int i=1;;i++){
		if(n%stand[i]==0){
			cout<<n/stand[i];
			break;
		}
	}
	return 0;
}

请大家看注释了好多问号的地方,这几处目前的输出依次是0 0 1(就是stand[0]) 但是明明没有改过stand[0],为什么会自己变呢

#include<bits/stdc++.h>
using namespace std;
const int N=100000;
bool stan[N]={0};
int stand[N]={0};
void Output(){
	for(int i=1;i<=stand[0];i++)cout<<stand[i]<<' ';
	cout<<endl;
}
void Sieve(){
	cout<<stand[0]<<endl;//??????????????????????????
//	stan[1]=1;
//	stan[N]=1;
	cout<<stand[0]<<endl;//?????????????????????????
	for(int i=2;i<=100;i++){
		if(!stan[i]){
			//cout<<i<<' '<<stand[0]<<endl;
			stand[0]++;
			stand[stand[0]]=i;
			//cout<<stand[0]<<' '<<stand[stand[0]]<<endl;
			Output();
			for(int j=i*2;j<=N;j+=i)stan[j]=1;
		}
	}
}
int main(){
	cout<<stand[0]<<endl;//???????????????????????
	Sieve();
	//for(int i=1;i<=10;i++)cout<<stand[i]<<endl;
	int n;
	cin>>n;
	for(int i=1;;i++){
		if(n%stand[i]==0){
			cout<<n/stand[i];
			break;
		}
	}
	return 0;
}

注释了修改stan的两行以后,输出又变成了0 0 0 这是为什么?求助

2024/9/5 20:31
加载中...