社区讨论

求问long double

学术版参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@logxrhgi
此快照首次捕获于
2023/11/02 16:39
2 年前
此快照最后确认于
2023/11/02 16:49
2 年前
查看原帖
RT
为何有时候两个相等的值程序判断不相等,如:
CPP
#include<bits/stdc++.h>
using namespace std;
const int N=10;
long double a;
int cnt=1,ans[N+10];
bool zs[N+10];
inline int rd(){
	int x=0,f=1;char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-')f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=x*10+s-'0';
		s=getchar();
	}
	return x*f;
}
inline void shai(){
	zs[1]=1;
   	for(int i=2;i<=N;i++){
	   if(!zs[i]){
	       ans[++cnt]=i;	
	   }
	   for(int j=2;j<=cnt;j++){
	   	   if(i*ans[j]>N)break;
		   zs[ans[j]*i]=1;
		   if(i%ans[j]==0){
		   	  break;
		   }
	   }
	}
	ans[1]=1;
}
int main(){
	cin>>a;
	printf("%.19Lf\n",a);
	long double o=0.3333333333333333333;
	if(o==a){
		cout<<"fk"<<endl;
	}
//	cout<<a<<endl;
	shai();
	for(int i=1;i<=cnt;i++){
		cout<<ans[i]<<endl;
	}
	for(int i=1;i<=cnt;i++){
		for(int j=i+1;j<=cnt;j++){
			long double l=ans[i];
			l/=ans[j];
			cout<<ans[i]<<" "<<ans[j]<<" ";
			printf("%.19Lf\n",l);
//			cout<<l<<endl;
			if(l==a){
				cout<<ans[i]<<" "<<ans[j]<<endl;
				return 0;
			}
		}
	}
	return 0;
}

输入样例为:

0.3333333333333333333

回复

5 条回复,欢迎继续交流。

正在加载回复...