萌新求助玄学问题
  • 板块学术版
  • 楼主lqt1217
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/1/8 19:48
  • 上次更新2024/1/8 22:31:31
查看原帖
萌新求助玄学问题
374340
lqt1217楼主2024/1/8 19:48

这个代码在g++ a.cpp -o a的命令行下输出很正常,但在加了-O2后全都输出了1。并且如果将里面的#define int __int128改成#define int long long后又没有问题了。 请问为什么呢,谢谢。

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define int __int128
#define ll long long
typedef pair<int, int> pii;
int a[15], tot;
int rd() {
  char ch= getchar();
  int t= 0;
  while(ch< '0'|| ch> '9') ch= getchar();
  while(ch>= '0'&& ch<= '9') t= (t<< 3)+ (t<< 1)+ ch- '0', ch= getchar();
  return t;
}
void div(int x) {
  for(int i= 2; i* i<= x; i++ ) {
    if(x% i== 0) {     
      a[++ tot]= 1;
      while(x% i== 0) a[tot]*= i, x/= i;
      cout<<(long long)a[tot]<<endl;
      cout<< endl;
    }
  }
}
signed main() {
  int T= rd(), mod= rd();
  div(mod);
  return 0;
}
2024/1/8 19:48
加载中...