Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么RE了,难道要用__int64?? 高手进来看一下。#include <iostream> #include <math.h> #include <fstream> using namespace std; #define Max 15000 struct prim{ int flag; //flag=1表示可以分解 int real; int virtl; void print(){ if(virtl!=1){ cout<<real<<"+"<<virtl<<"j, "<<real<<"-"<<virtl<<"j"; }else{ cout<<real<<"+j, "<<real<<"-j"; } } } p[Max]; int pp[Max]; int num; int cmp(const void *a1,const void *a2){ int mm=*(int*)a1; int nn=*(int*)a2; prim s=p[mm]; prim t=p[nn]; if(s.real!=t.real)return (s.real-t.real); else{ return (s.virtl-t.virtl); } } void init(){ num=1; p[0].flag=1; p[0].real=p[0].virtl=1; pp[0]=2; for(int i=3;num<Max;i++){ int isprim=1; for(int j=0;pp[j]<=sqrt(i);j++){ if(i%pp[j]==0){ isprim=0; break; } } if(isprim==1){ pp[num]=i; if(i%4==1){ p[num].flag=1; p[num].virtl=sqrt(pp[num]); p[num].real=sqrt(pp[num]-p[num].virtl*p[num].virtl ); }else{ p[num].flag=0; } num++; } } } void main(){ init(); int n; int tc=1; while(cin>>n){ cout<<"Case #"<<tc++<<": "; if(n==1)cout<<"j, -j"<<endl; else{ int ndivid[1000]; int ndn=0; int cdivid[1000]; int cdn=0; for(int i=0;pp[i]<=n;i++){ if(n%pp[i]==0){ if(p[i].flag==1){ cdivid[cdn++]=i; }else{ ndivid[ndn++]=i; } } } int total=cdn+ndn; if(cdn!=0){ qsort(cdivid,cdn,sizeof(cdivid[0]),cmp); for(int j=0;j<cdn;j++){ p[cdivid[j]].print(); if((j+1)!=total){ cout<<", "; }else{ cout<<endl; } } } if(ndn!=0){ for(int j=0;j<ndn;j++){ cout<<pp[ndivid[j]]; if((j+1)!=ndn){ cout<<", "; } } cout<<endl; } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator