POJ3101 大数+LCM
发布时间:2020-12-14 03:36:30 所属栏目:大数据 来源:网络整理
导读:不是很难,倒是写大数类用了很久,由于要考虑到中间过程会出现long long 的情况,大数类里面的东西要用long long 写,包括,除法,取模运算什么的。 N个分数的的最小公倍数是分子的最小公倍数,分母的最大公约数。 (1/2)/(1/t1-1/t2)得到时间间隔,化简得到t
不是很难,倒是写大数类用了很久,由于要考虑到中间过程会出现long long 的情况,大数类里面的东西要用long long 写,包括,除法,取模运算什么的。 N个分数的的最小公倍数是分子的最小公倍数,分母的最大公约数。 (1/2)/(1/t1-1/t2)得到时间间隔,化简得到t1*t2/(2*(t2-t1)) #include <string.h> <stdio.h> <math.h> <stdlib.h> <iostream> <algorithm> #define NNN cout<<'n'; using namespace std; long long a[1111],b]; long que=0long absMy(long aa) { if(aa<) return -aa; else return aa; } class BigInteger { public: long num1000]; long len; BigInteger() { len; memset(num,sizeof)); } BigIntegerchar* ss) )); long& i=this->len; long lenofss=strlen(ss); char s10]={0}; for(i;lenofss/4-=) { strncpy(s+lenofss-4); ->num[i++]=atoi); } (lenofss{ memset)); strncpy} } BigIntegerlong s) { len; memset)); while>10000) { num[len++]=s%; s/=; } ==) len1; } void Print{ long i; printf("%lld"[len-1]); ->len-2;i>=--) { printf"%04lld"]); } //printf("n"); } BigInteger Times(BigInteger sec)//该数本身没有变化,只是返回了结果 ; BigInteger ans<len++) { jw; ans.len=i; (j;j<sec++) { jw+=]*sec.num[j]+ans[ans]; ans++]=jw; jw; } (jw) +=ans} return ans; } BigInteger plusonedo { num]++; num[i+1]+=num]/; num]%=; i++; }]<9999); *} BigInteger operator+(const BigInteger& sec{ bool isUpfalse; BigInteger tmp=*; <++) { (isUp) { tmp]++; (tmp]>=) { tmp]=; isUptrue; } } ]+sec]<=]+=sec]; isUp; else ]=tmp]-; isUp} } long maxn=tmp>sec?tmp:sec[maxn]!=) tmp++; else tmp=maxnreturn tmp-(//big-small bool isBorrow(isBorrow]-=; ) tmp]<sec]) ]+-sec]; isBorrow]-=sec999{ ) break; ==-=i} BigInteger *(const BigInteger sec{ return ->Times(sec); /(long sec//big/small { /*if(sec==1) return *this;*/ BigInteger ret=len{ ret]=(num]+down*)/sec; down=num-ret} ret=len(ret[ret.len]==&&ret) ret--; return ret%({ BigInteger tmp; BigInteger shang/sec; BigInteger big_sec=BigInteger); BigInteger ans-shang*big_sec} BigInteger& ++() ->plusone(); } bool <=({ (len) --) ]>sec]) >=(==(!=sec]!=secconst !=]==secelse <(; else >(!=(} /*BigInteger GCD(const BigInteger& first,const BigInteger& sec) { return first%sec==0?sec:GCD(sec,first%sec); } BigInteger LCM(const BigInteger& first,102); font-style:italic"> return first/GCD(first,sec)*sec; }*/ long gcdlong b(a<b) swap); return b?a:gcd(b%b); } long lcmreturn a/gcd)*bint main() { //freopen("D:/1.txt","r",stdin); //freopen("D:/my.txt","w",stdout); long n; long first; cin>>n<n++) long time; cin>>time(!i) first=time(first!=time{ long tmp=gcd*time2*absMy-time)); a[que]=first/tmp; b++]=)/tmp; first} (que{ printf"%lld %lld"]); } else long gcdnum; gcdnum<que{ gcdnum(gcdnum} long ans2=gcdnum; BigInteger a0]); BigInteger a1]); BigInteger lcmnum=a0*a1]); BigInteger bigai; BigInteger modn_biglong tmpgcd{ modn_big=lcmnum%a]; long modn=modn_big]*+modn_big]; tmpgcd); bigai]); lcmnum=bigai*lcmnum/tmpgcd; /*cout<<"TMPGCDis: "; lcmnum.Print(); NNN cout<<"lcmis: "; NNN*/ } lcmnum.Print(); printf" %lld} } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |