Advertisement
Guest User

Untitled

a guest
May 29th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. ///****************************Bismillahir Rahmanir Rahim***************************///
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. typedef long double ld;
  8. typedef vector<int> vi;
  9. typedef vector<double> vd;
  10. typedef vector<ll> vl;
  11. typedef vector<vi> vvi;
  12. typedef vector<vl> vvl;
  13. typedef pair<int,int> pii;
  14. typedef pair<double, double> pdd;
  15. typedef pair<ll, ll> pll;
  16. typedef vector<pii> vii;
  17. typedef vector<pll> vll;
  18. typedef vector<pdd> vdd;
  19.  
  20. #define PB push_back
  21. #define F first
  22. #define S second
  23. #define MP make_pair
  24. #define endl '\n'
  25. #define all(a) (a).begin(),(a).end()
  26. #define rall(a) (a).rbegin(),(a).rend()
  27. #define sz(a) a.length()
  28.  
  29. const double PI = acos(-1);
  30. const double eps = 1e-9;
  31. const int inf = 2000000000;
  32. const ll infLL = 9000000000000000000;
  33. #define MOD 1000000007
  34. //#define harmonic(n) 0.57721566490153286l+log(n)
  35.  
  36. #define mem(a,b) memset(a, b, sizeof(a) )
  37. #define gcd(a,b) __gcd(a,b)
  38. #define lcm(a,b) (a*(b/gcd(a,b)))
  39. #define sqr(a) ((a) * (a))
  40.  
  41. #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  42. #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
  43.  
  44. typedef vector<int>::iterator vit;
  45. typedef set<int>::iterator sit;
  46.  
  47. inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
  48. inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
  49. inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }
  50.  
  51. int dx4[] = {0, 0, +1, -1};
  52. int dy4[] = {+1, -1, 0, 0};
  53. int dx8[] = {+1, 0, -1, 0, +1, +1, -1, -1};
  54. int dy8[] = {0, +1, 0, -1, +1, -1, +1, -1};
  55.  
  56. inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
  57. inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
  58. inline bool isIntege(double num) { return (num==(int)num); }
  59. inline bool collinear(int x1, int y1, int x2, int y2, int x3, int y3) {return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2);}
  60. inline double coDist(double x1,double y1,double x2,double y2) { return sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))); }
  61. inline double TriangleAreaWithSide(double a,double b,double c){double s =(a+b+c)/2; double area=sqrt(s*(s-a)*(s-b)*(s-c));return area;}
  62. inline double area3(double x1,double y1,double x2,double y2,double x3,double y3){double A=abs((x1*y2+x2*y3+x3*y1)-(y1*x2+y2*x3+y3*x1));A/=2.0;return A;}
  63. inline ld degreetoradian(ld x){ld val=PI*x;val/=(180.0);return val;}
  64. inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
  65. inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
  66. inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
  67. inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
  68. inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
  69. inline ll modInverse(ll a) { return modPow(a, MOD-2); }
  70. inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
  71. inline bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
  72. inline bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
  73. inline bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
  74. inline bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true; else return false;}
  75. inline bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
  76. inline bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}
  77.  
  78. struct edge{int p, q, w;};
  79. bool cmp ( edge &a, edge &b ){return a.w < b.w;}
  80. string to_s(int t){stringstream ss;ss << t;return ss.str();}
  81. /*
  82. bool seive[1010000];
  83. vi prime;
  84. void seiveGen(int limit) {
  85. limit += 100;
  86. int sqrtn = sqrt(limit);
  87. for(int i = 3; i <= sqrtn; i += 2) {
  88. if(!seive[i>>1]) {
  89. for(int j = i * i; j < limit; j += i + i) {
  90. seive[j>>1] = 1;
  91. }
  92. }
  93. }
  94. prime.PB(2);
  95. for(int i = 3; i < limit; i += 2) {
  96. if(!seive[i>>1]) prime.PB(i);
  97. }
  98. }
  99. */
  100. /*
  101. vi PrimeF;
  102.  
  103. void primeFactorize( int n ) {
  104.  
  105. for( int i = 0; prime[i]*prime[i] <=n ; i++ ) {
  106. if( n % prime[i] == 0 ) {
  107. while( n % prime[i] == 0 ) {
  108. n /= prime[i];
  109. PrimeF.PB( prime[i] );
  110. }
  111. }
  112. }
  113. if( n > 1 ) {
  114. PrimeF.PB(n);
  115. }
  116. }
  117. */
  118. //
  119. //debug
  120. //#ifdef
  121. template < typename F, typename S >
  122. ostream& operator << ( ostream& os, const pair< F, S > & p ){return os << "(" << p.first << ", " << p.second << ")";}
  123. template < typename T >
  124. ostream &operator << ( ostream & os, const vector< T > &v ){os << "{";for(auto it = v.begin(); it != v.end(); ++it) {if( it != v.begin() ) os << ", ";os << *it;}return os << "}";}
  125. template < typename T >
  126. ostream &operator << ( ostream & os, const set< T > &v ){os << "[";for(auto it = v.begin(); it != v.end(); ++it) {if( it != v.begin() ) os << ", ";os << *it;}return os << "]";}
  127. template < typename T >
  128. ostream &operator << ( ostream & os, const multiset< T > &v ){os << "[";for(auto it = v.begin(); it != v.end(); ++it) {if( it != v.begin() ) os << ", ";os << *it;}return os << "]";}
  129. template < typename F, typename S >ostream &operator << ( ostream & os, const map< F, S > &v ){os << "[";for(auto it = v.begin(); it != v.end(); ++it) {if( it != v.begin() ) os << ", ";os << it -> first << " = " << it -> second ;}return os << "]";}
  130. #define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
  131. clock_t tStart = clock();
  132. #define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
  133. void faltu () {cerr << endl;}
  134. template <typename T>
  135. void faltu( T a[], int n ) {for(int i = 0; i < n; ++i) cerr << a[i] << ' ';cerr << endl;}
  136. template <typename T, typename ... hello>
  137. void faltu( T arg, const hello &... rest) {cerr << arg << ' '; faltu(rest...);}
  138. //#else
  139. //#define dbg(args...)
  140. /*
  141. ************************************************************************************
  142. transform(s.begin(),s.end(),s.begin(),::tolower);///change of uppercase to lowercase of any string
  143. cout << setprecision(12) << fixed; //main(_) er 1st line
  144. freopen("input.txt","r",stdin);
  145. freopen("output.txt","w",stdout);
  146. */
  147. /*======================= TEMPLATE =======================*/
  148.  
  149. ll expo( ll x,ll n){
  150.  
  151. if(n==0)
  152. return 1;
  153. if(n==1)
  154. return x;
  155. if(n%2)
  156. return modMul(expo(x,n-1),x);
  157. else{
  158.  
  159. ll temp=expo(x,n/2)%MOD;
  160. return modMul(temp,temp);
  161. }
  162. }
  163. int main()
  164. {
  165. optimize();
  166.  
  167. int t;
  168. cin>>t;
  169.  
  170. while(t--){
  171.  
  172. ll n,s;
  173. cin >> n >> s;
  174.  
  175. ll x=0,y=0;
  176.  
  177. x=s/n;
  178. y=(s%n);
  179.  
  180. ll temp1 = expo(x,n-y)%MOD;
  181. ll temp2 = expo(x+1,y)%MOD;
  182. //dbg(temp1,temp2,x,y);
  183. ll ans=modMul(temp1,temp2);
  184.  
  185. cout<<ans<<endl;
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement