题目链接  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. BInder浅析

    Binder是什么 Binder是运行在Android内核态用于进程间通信(IPC)的驱动,采用C/S架构,由三项基本组件组成:Binder服务端,Binder驱动,应用程序客户端. 为什么要用Bin ...

  2. Json 转换 1 转成 true 0 转成false

  3. scp 将数据从一台linux服务器复制到另一台linux服务器

    原文地址:http://www.cnblogs.com/peida/archive/2013/03/15/2960802.html  完整内容参考原文! scp 是secure copy的简写,用于在 ...

  4. Python网络编程(OSI模型、网络协议、TCP)

    前言: 什么是网络? 网络是由节点和连线构成,表示诸多对象及其相互联系. 在数学上,网络是一种图,一般认为专指加权图. 网络除了数学定义外,还有具体的物理含义,即网络是从某种相同类 型的实际问题中抽象 ...

  5. javascript replace 替换全部字符

    $("#pageNote").html($("#note3").val().replace(/ /g, "").replace(/<b ...

  6. vADC-KVM and vADC-ESX.ovf

    vADC-KVM  and  vADC-ESX.ovf vADC-ESX.ovf.xml <?xml version="1.0" encoding="UTF-8&q ...

  7. 刷题总结——Throw nails(hdu4393)

    题目: Problem Description The annual school bicycle contest started. ZL is a student in this school. H ...

  8. HDU 5752

    Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  9. python登录知乎

    #coding:utf-8 import requests import urllib3 import time class Zhihu: def __init__(self): self.login ...

  10. Python之面向对象:闭包和装饰器

    一.闭包 1. 如果一个函数定义在另一个函数的作用域内,并且引用了外层函数的变量,则该函数称为闭包. def outter(): name='python' def inner(): print na ...