玲珑杯 Six and One 【暴力】

1095 - Six and One

Time Limit:1s Memory Limit:128MByte

Submissions:168Solved:45

DESCRIPTION

Given the integers LL and RR, your task is calculating the count of the integer nn which meet the following conditions:

For instance, 11, 66, 1616, 3636, 6161, 37213721 are some integers which meet the conditions.

INPUT
The first line contains a positive integer TT, which represents there are TT test cases.The following is test cases. For each test case:The only line contains two positive integer LL and RR. 1T105,1LR10101≤T≤105,1≤L≤R≤1010
OUTPUT
For each test case, output in one line, contains one integer, which represents the count of the integers which meet the conditions.
SAMPLE INPUT
41 1016 3660 703720 3722
SAMPLE OUTPUT
2221

---------------------------------------------------------------------------------------------------

所有由6和1组成的<=1e10数  有<3^10个(每位从0,1,6中选择)

果断dfs枚举

由6,1组成的数 除了1外 都>=6

m个数连乘 可以看做m<=log6(1e10)

m也不大  于是再枚举每个数的k次幂

放set里发现居然只有2000+个数

继续暴力 预处理出所有数+2分就过了....

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
#include<queue>
#include<sstream>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007
#define pll pair<ll,ll>
#define pid pair<int,double>

const ll N = 1e10;

vector<ll>a;

void init61(ll x){//求出由6和1组成的数
    ll x1=x*10+1;
    ll x2=x*10+6;
    if(x1<=N){
        a.push_back(x1);
        init61(x1);
    }
    if(x2<=N){
        a.push_back(x2);
        init61(x2);
    }
}

set<ll>aset;

inline bool greaterThenN(ll a,ll b){//a*b>N? 乘法改除法防溢出
    double c=(double)a/N;
    return c*b>1;
}

void slove(){
    sort(a.begin(),a.end());
    for(int i=1;i<a.size();++i){//求出所有t=a[i]^k 满足t<=N
        ll x=a[i];
        ll t=1;
        while(1){
            if(greaterThenN(t,x)){
                break;
            }
            t*=x;
            aset.insert(t);
        }
    }
    for(auto it1=aset.cbegin();it1!=aset.cend();++it1){//枚举连乘
        for(auto it2=aset.cbegin();it2!=it1;++it2){
            if(greaterThenN(*it1,*it2)){
                break;
            }
            aset.insert(*it1*(*it2));
        }
    }
    a.clear();
    a.push_back(1);
    for(auto it=aset.cbegin();it!=aset.cend();++it){
        a.push_back(*it);
        //cout<<a.back()<<endl;
    }
}

int main()
{
    //freopen("/home/lu/Documents/r.txt","r",stdin);
    //freopen("/home/lu/Documents/w.txt","w",stdout);
    init61(0);
    slove();
    int n;
    scanf("%d",&n);
    while(n--){
        ll l ,r;
        scanf("%lld%lld",&l,&r);
        auto it1=lower_bound(a.begin(),a.end(),l);
        auto it2=upper_bound(a.begin(),a.end(),r);
        printf("%d\n",it2-it1);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值