为什么会T掉

P2092 数字游戏

。。。i<=5*10^6
by 空江白叶 @ 2019-06-15 09:02:41


int*int会炸的呀
by minstdfx @ 2019-06-15 09:03:05


@[空江白叶](/space/show?uid=113804) 爆int然后就一直循环了呀
by yu__xuan @ 2019-06-15 09:03:16


哦,没想到这一点,谢谢dalao
by 空江白叶 @ 2019-06-15 09:04:29


炸了
by QAQ_QAQ @ 2019-06-15 09:34:44


我都用了筛法了,为什么还有两个点TLE? ```cpp #include<iostream> #include<math.h> using namespace std; bool judge(long long a){ if(a==2||a==3){ return 1; } if(a<2||(a%6!=1)&&(a%6!=5)){ return 0; } for(long long i=5;i<=sqrt(a);i+=6){ if(a%i==0||a%(i+2)==0){ return 0; } } return 1; } int main(){ long long a; cin>>a; if(judge(a)||a==1){ cout<<1<<endl<<0; return 0; } long long s[44];//2^44>10^13 int cnt=0; while(a%2==0){ s[cnt]=2; cnt++; a/=2; } while(a%3==0){ s[cnt]=3; cnt++; a/=3; } for(long long i=5;i<=a;i+=6){ while(a%i==0){ s[cnt]=i; cnt++; a/=i; } if(a==1){ break; } while(a%(i+2)==0){ s[cnt]=i+2; cnt++; a/=i+2; } if(a==1){ break; } } if(cnt==2){ cout<<2; return 0; } cout<<1<<endl<<s[0]*s[1]; } ```
by Ricken @ 2019-08-28 14:28:59


为啥爆int会一直循环呀
by jasonliujiahua @ 2023-01-16 16:31:43


|