- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long unsigned
- #define N 10000000000
- #define M 100000007
- ll numbers[1000006];
- int cnt = 0;
- void generate_num(){
- ll mul;
- for(ll i = 2; i <= 1000005; i++){
- mul = i*i;
- //printf("mul = %llu\n", mul);
- while(mul<= N){
- numbers[cnt++] = mul;
- mul = mul*i;
- }
- }
- sort(numbers, numbers+cnt);
- cnt = unique(numbers, numbers+cnt) - numbers;
- numbers[cnt++] = 1000000000000000;
- //cout<<"count = "<<cnt<<endl;
- //for(int i = 0; i <100; i++) cout<<numbers[i]<<" ";
- }
- ll fact[1000005];
- ll bigmod(ll p, ll q){
- if(q == 1) return p%M;
- if(q%2 == 0){
- ll a = bigmod(p, q/2);
- return ((a%M)*(a%M))%M;
- }
- else{
- ll a = bigmod(p, q-1);return (a*p)%M;
- }
- }
- void pre(){
- fact[0] = 1;
- for(int i = 1; i <1000005; i++) fact[i] = (i*(fact[i-1]%M))%M;
- }
- int main(){
- generate_num();
- pre();
- int ts;
- scanf("%d", &ts);
- for(int k = 1; k <= ts; k++){
- ll a, b;
- scanf("%llu%llu", &a, &b);
- int l = lower_bound(numbers, numbers+cnt, a)-numbers;
- int r = upper_bound(numbers, numbers+cnt, b)-numbers;
- int elements = r-l;
- if(elements == 0){
- printf("Case %d: 0\n", k);
- continue;
- }
- ll s = bigmod((fact[elements+1]*fact[elements])%M,M-2)%M;
- ll p = (fact[2*elements]*s)%M;
- printf("Case %d: %llu\n", k,p);
- }
- return 0;
- }
Saturday, 29 July 2017
Lightoj 1170 - Counting Perfect BST
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment