Tranvick

Длинка

Dec 29th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #define ll long long
  5. #define N 11111
  6. #define P 1000000000
  7. using namespace std;
  8.  
  9. class bigint{
  10.     public:
  11.     int sz;
  12.     ll a[N];
  13.     bigint(ll x=0){
  14.         memset(a,0,sizeof(a));
  15.         sz=0;
  16.         while (x){
  17.             a[++sz]=x%P;
  18.             x/=P;
  19.         }
  20.         if (!sz) ++sz;
  21.     }
  22.     void print(){
  23.         printf("%I64d",a[sz]);
  24.         for (int i=sz-1;i>=1;i--) printf("%.9I64d",a[i]);
  25.     }
  26.     friend ostream& operator << (ostream& output, bigint & q){
  27.         q.print();
  28.         return output;
  29.     }
  30.     ll & operator [] (int x){
  31.         return a[x];
  32.     }
  33.     friend bool operator < (bigint & p,bigint &q){
  34.         if (p.sz<q.sz) return 1;
  35.         if (p.sz>q.sz) return 0;
  36.         for (int i=p.sz;i;i--){
  37.             if (p[i]>q[i]) return 0;
  38.             if (p[i]<q[i]) return 1;
  39.         }
  40.         return 0;
  41.     }
  42.     friend bool operator == (bigint & p,bigint & q){
  43.             return !(p<q) && !(q<p);
  44.     }
  45.     friend bool operator != (bigint & p, bigint & q){
  46.         return p<q || q<p;
  47.     }
  48.     friend bool operator >= (bigint & p,bigint & q){
  49.         return !(p<q);
  50.     }
  51.     friend bool operator <= (bigint &p, bigint & q){
  52.         return !(q<p);
  53.     }
  54.     friend bool operator > (bigint &p, bigint & q){
  55.         return q>p;
  56.     }
  57.     friend bigint operator + (bigint &a,bigint &b){
  58.         bigint res;
  59.         int n=max(a.sz,b.sz);
  60.         for (int i=1;i<=n;i++){
  61.             res[i]=a[i]+b[i]+res[i];
  62.             res[i+1]=res[i]/P;
  63.             res[i]%=P;
  64.         }
  65.         if (res[n+1]) ++n;
  66.         res.sz=n;
  67.         return res;
  68.     }
  69.     friend bigint operator * (bigint &a,bigint &b){
  70.         bigint res;
  71.         int n=a.sz,m=b.sz,k=n+m-1;
  72.         for (int i=1;i<=n;i++)
  73.             for (int j=1;j<=m;j++){
  74.                 res[i+j-1]=a[i]*b[j]+res[i+j-1];
  75.                 res[i+j]+=res[i+j-1]/P;
  76.                 res[i+j-1]%=P;
  77.             }
  78.         if (res[k+1]) ++k;
  79.         res.sz=k;
  80.         return res;
  81.     }
  82.     friend bigint operator - (bigint &a,bigint &b){
  83.         bigint res;
  84.         int k=a.sz;
  85.         for (int i=1;i<=k;i++){
  86.             res[i]+=a[i]-b[i];
  87.             if (res[i]<0){
  88.                 res[i]+=P;
  89.                 res[i+1]--;
  90.             }
  91.         }
  92.         while (res[k]==0) --k;
  93.         res.sz=k;
  94.         return res;
  95.     }
  96.     friend void operator -=(bigint &p,bigint & q){
  97.         p=p-q;
  98.     }
  99.     friend void operator +=(bigint &p,bigint & q){
  100.         p=p+q;
  101.     }
  102.     friend void operator *=(bigint &p, bigint & q){
  103.         p=p*q;
  104.     }
  105.     friend bigint operator ^ (bigint & p, int y){
  106.         bigint x=p,res=1;
  107.         while (y){
  108.             if (y&1) res*=x;
  109.             y>>=1;
  110.             x*=x;
  111.         }
  112.         return res;
  113.     }
  114.     friend bigint operator ! (bigint & p){
  115.         bigint res=1,I;
  116.         int n=p[1];
  117.         for (int i=1;i<=n;i++){
  118.             I=i;
  119.             res=res*I;
  120.         }
  121.         return res;
  122.     }
  123.      
  124. };
  125.  
  126. int main(){
  127.     int x,y;
  128.     cin>>x>>y;
  129.     bigint f1=x;
  130.     bigint f=f1^y;
  131.     cout<<f1<<"^"<<y<<"="<<f;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment