zoj 3629 Treasure Hunt IV 打表找规律

H - Treasure Hunt IV

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

  Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a from b in front of her.
  Alice was very excited but unfortunately not all of the treasures are real, some are fake.
  Now we know a treasure labled n is real if and only if [n/1] + [n/2] + ... + [n/k] + ... is even.
  Now given 2 integers a and b, your job is to calculate how many real treasures are there.

Input

  The input contains multiple cases, each case contains two integers a and b (0 <= a <= b <= 263-1) seperated by a single space. Proceed to the end of file.

Output

  Output the total number of real treasure.

Sample Input

0 2
0 10

Sample Output

1
6

题意:给你一个Long long范围的区间,然后问里面有多少个数,满足n/1+n/2+n/k……加起来等于一个偶数题解:首先打表,然后我们发现这种数是扎堆存在的,[0,1),[4,9),[16,25),……然后我们就这样子找规律,然后一个等差数列求和就好啦!
LL solve(LL n)
{
    LL m = (LL)sqrt(n*1.0);
    LL sum=0;
    if(m%2==0) sum = n-m*m;
    if(m%2==1) m++;
    LL j=m/2;
    sum=sum-j+2*j*j;
   // sum=sum+2*j*j-j;
    return sum;
}
int main()
{
    LL n,m;
    while(scanf("%llu%llu",&n,&m)>0)
    {
        n++,m++;
        LL ans=solve(n-1);
        LL cur =solve(m);
        printf("%llu\n",cur-ans);
    }
    return 0;
}
时间: 2024-11-11 19:39:56

zoj 3629 Treasure Hunt IV 打表找规律的相关文章

zoj 3629 Treasure Hunt IV(找规律)

Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a fromb in front of her.Alice was very excited but unfortunately not all of the treasures are real, some are fake.Now w

ZOJ3629 Treasure Hunt IV(找规律,推公式)

Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a from b in front of her. Alice was very excited but

zoj Treasure Hunt IV

Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a from b in front of her.Alice was very excited but

【ZOJ】3785 What day is that day? ——浅谈KMP应用之ACM竞赛中的暴力打表找规律

首先声明一下,这里的规律指的是循环,即找到最小循环周期.这么一说大家心里肯定有数了吧,“不就是next数组性质的应用嘛”. 先来看一道题 ZOJ 3785 What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple tes

zoj 3626 Treasure Hunt I (树形dp)

题目大意: 给出一棵树,求出从起点开始走m长度最后回到起点,所能得到的宝藏的最大价值. 思路分析: 通过一次dfs可以得到的是子树到根节点的所有距离的最大值. 现在的问题就是他走完一颗子树可以去另外一颗子树. 所以在回溯到根的时候要统计其他子树上互补距离的最大值. dp[i] [j] 表示i为根节点,在i的子树中走j步然后回到i所能拿到的最大价值. 转移方程就是 dp[x][i+2*len]=max(dp[x][i+2*len],dp[v][j]+dp[x][i-j]); v为x的子树的根,le

[zoj 3626]Treasure Hunt I 树DP

<span style="font-family: Arial, Helvetica, Verdana, sans-serif; background-color: rgb(255, 255, 255);">Treasure Hunt I</span> Time Limit: 2 Seconds      Memory Limit: 65536 KB Akiba is a dangerous country since a bloodsucker living

hdu 2147 kiki&#39;s game(DP(SG)打表找规律)

题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n,m<=2000) 思路: dp[i][j]=0,说明从(i,j)这个点到时左下角先手败.dp[i][j]=1则先手胜. 然后记忆搜.但是记忆搜会超时. 搜完把整张表打出来,发现规律了,,,,然后,,,代码剩几行了. 代码: ///打表观察 /* int f[2005][2005]; int go(in

hdu_5894_hannnnah_j’s Biological Test(打表找规律)

题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律,最后发现答案为n*C(n-m*k-1,n-m*k-m)/m 然后这里求组合要预处理一下,逆元也预处理一下 最后还要特判m为1的情况 1 #include<cstdio> 2 typedef long long ll; 3 const int P=1e9+7; 4 5 const int maxn

【NOIP 模拟赛】中值滤波 打表找规律

对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> const int N=500010; int n,ans,A[N]; inline int Max(int x,int y){ return x>y?x:y; } int main(){ scanf("%d",&n); int last,now,P=0; for(int i