题目链接  ECL-Final 2017 Problem D

题意  给定$2*10^{5}$组询问,每个询问求$l$到$r$之间有多少个符合条件的数

如果一个数小于等于$10^{15}$, 并且能被分割成一个至少有$3$项的递增等比数列(公比可以不为整数)

那么这个数是符合条件的。

比赛的时候我大概觉得这应该不是数位DP,是一个比较trick的枚举题。

但是我总感觉哪个地方不太对,或者说是没有写这道题的意识,一直瘫在那里。

今天AC了这个题之后真的后悔莫及,但是一点用都没有。

从至少有$3$项这个条件入手。

假设数列只有$3$项。

因为数列递增,所以第二项一定不超过$10^{5}$,

所以等比数列的公比

$\frac{q}{p} <= \frac{a_{2}}{a_{1}} <= a_{2} <= 10^{5}$

设第一项为$kp^{2}$, 第二项为$kpq$, 第三项为$kq^{2}$

那么$kpq <= 10^{5}$,即$pq <= 10^{5}$;

枚举符合条件的$p$和$q$,发现枚举量不超过$4*10^{5}$;

在这个基础上枚举$k$,然后求出整个数列,并考虑那些项数大于$3$的数列,

最后sort一下二分查找就可以了。

#include <ctime>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int N = 1e5 + 10; LL a[N * 100];
LL ten[20];
LL l, r;
int cnt = 0;
int T, ca = 0; int solve(LL x){ return upper_bound(a + 1, a + cnt + 1, x) - a - 1; } inline int calc(LL x){
int ret = 0;
for (; x; x /= 10) ++ret;
return ret;
} LL mer(LL x, LL y){ return x * ten[calc(y)] + y; } int main(){ ten[0] = 1ll;
rep(i, 1, 18) ten[i] = ten[i - 1] * 10ll; rep(p, 1, 1e5){
rep(q, p + 1, 1e5){
if (1ll * p * q >= 1e5) break;
if (__gcd(p, q) > 1) continue; rep(k, 1, 1e5 / p / q){
LL x = 1ll * k * p * p;
LL y = 1ll * k * p * q;
LL z = 1ll * k * q * q; int cnt_len = calc(x) + calc(y) + calc(z);
if (cnt_len > 15) break; LL now = mer(mer(x, y), z);
a[++cnt] = now; while (true){
if (calc(z) >= 9) break;
if (z * z % y > 0) break;
LL nw = z * z / y;
int nwlen = calc(nw);
if (cnt_len + nwlen > 15) break;
cnt_len += nwlen;
now = mer(now, nw);
a[++cnt] = now;
y = z;
z = nw;
}
}
}
} sort(a + 1, a + cnt + 1);
scanf("%d", &T);
while (T--){
scanf("%lld%lld", &l, &r);
printf("Case #%d: %d\n", ++ca, solve(r) - solve(l - 1));
} return 0;
}

Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,D题,枚举剪枝)的更多相关文章

  1. Codeforces Gym 101194C Mr. Panda and Strips(2016 EC-Final,区间DP预处理 + 枚举剪枝)

    题目链接  2016 EC-Final 题意  现在要找到数列中连续两个子序列(没有公共部分).要求这两个子序列本身内部没有重复出现的数.   求这两个子序列的长度的和的最大值. 首先预处理一下.令$ ...

  2. Gym 101194F Mr. Panda and Fantastic Beasts

    #include<bits/stdc++.h> using namespace std; #define ms(arr,a) memset(arr,a,sizeof arr) #defin ...

  3. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...

  4. 【2-SAT】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    先反复地扫(不超过n次),把所有可以确定唯一取法的给确定下来. 然后对于剩下的不能确定的,跑2-SAT.输出可行解时,对于a和¬a,如果a所在的强连通分量序号在¬a之前,则取a,否则不取a.如果a和¬ ...

  5. hdu6007 Mr. Panda and Crystal 最短路+完全背包

    /** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...

  6. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  7. H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)

    Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday. It is k ...

  8. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  9. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

随机推荐

  1. 打开Vim/Vi代码高亮

    由于新装Vim/Vi 默认是没有打开代码高亮配置的,就看到有朋友一次次到网上去找各种配置.其实Vim默认带来配置文件的样本的,只需拷贝过来就可使用. 在用户根目录(~)中新建vim的配置文件 .vim ...

  2. 《Cracking the Coding Interview》——第11章:排序和搜索——题目5

    2014-03-21 21:37 题目:给定一个字符串数组,但是其中夹杂了很多空串“”,不如{“Hello”, “”, “World”, “”, “”, “”, “Zoo”, “”}请设计一个算法在其 ...

  3. python学习笔记一:数据类型

    一.Python文件类型 1.源代码 hello.py: 1 #!/usr/bin/python 2 print "hello world" 2.字节代码:python源文件经编译 ...

  4. day04_08-while查询所有行

    <?php $link = @mysql_connect('localhost','root',''); mysql_query('use test',$link); mysql_query(' ...

  5. IntelliJ IDEA 注释模版 输入/**后 不显示配置好的模板

    简单一句话就是 当你在live templetes里配置好以后,记住abbreviation:输入框里的字母 比如我的是cc ,我要想写注释怎么办? 在方法上输入 /*cc 然后按tab键就出来了

  6. django的聚合函数和aggregate、annotate方法使用

    支持聚合函数的方法: 提到聚合函数,首先我们要知道的就是这些聚合函数是不能在django中单独使用的,要想在django中使用这些聚合函数,就必须把这些聚合函数放到支持他们的方法内去执行.支持聚合函数 ...

  7. php连接数据库增删改查----多条件查询

    关于查询,可以直接写在主页面上 来进行查询 首先,先建立一个表单 <form method="post" action="crud.php"> &l ...

  8. maven学习(十六)——使用Maven构建多模块项目

    在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层).dao(数据库访问层).service(业务逻辑层).web(表现层),这样分层之 ...

  9. intellij idea 2017 快捷键(提高工作效率)

    1.Shift+Enter Annotation annotation = c.getAnnotation(A.class); 这个时候你写代码的时候可能光标在c.getAnno中的某一个位置,那么你 ...

  10. jquery radio 行选中 操作

    想实现点击一行中任意位置 此行的 radio 选中. function rowClick(t) { var id = $(t).attr("id").substr(3, 1); / ...