Wednesday 22 June 2016

POWER CALCULATE:

#include <bits/stdc++.h>
    using namespace std;
    #define LL long long int
    
    
    LL pow(LL a, LL b, LL mod) {
        LL x = 1, y = a;
        while(b > 0) {
            printf("b=%d\n",b);
            if(b%2 == 1) {
                 printf("%d %d\n",x,y);
                x=(x*y);
                if(x>mod)
                x%=mod;
            }
            y = (y*y);
            if(y>mod)
            y%=mod;
               b /= 2;
        printf("x=%d\n",x);  
        }
        return x;
    }
    int main()
    {
        LL A,B,MOD=1000000007;
        cin>>A>>B;
        cout<<pow(A,B,MOD)<<endl;
        return 0;
    }





 #include <bits/stdc++.h> 
 using namespace std;

int main()
  {
 int t;
 long long a,x,d,n,m,ans;
 cin >> t;
 while ( t-- ) {
        cin >> n >> m;
         ans = 0;
        a = 1;
        x = min(n,m);
         d = m+1;
         ans += (x*(2*a + (x-1)*d))/2;
         d = n+1;
        ans += (x*(2*a + (x-1)*d))/2;
        cout << ans << endl;
  }
   return 0;

}

No comments:

Post a Comment