[BZOJ3817]Sum】的更多相关文章

[BZOJ3817]Sum 试题描述 给定正整数N,R.求 输入 第一行一个数 T,表示有 T 组测试数据. 接下来 T 行,每行两个正整数 n,r. 输出 输出 T 行,每行一个整数表示答案. 输入示例 输出示例 - 数据规模及约定 对于 100% 的数据,满足 n≤10^9,r≤10^4,T≤10^4. 题解 新技能:类欧几里得算法. #include <iostream> #include <cstdio> #include <cstdlib> #include…
设$t=\sqrt r$,原题转化为$\sum_{x=1}^n(4*\lfloor\frac{tx}2\rfloor-2*\lfloor tx\rfloor+1)$考虑如何求$\sum_{x=1}^n\lfloor\frac{bt+c}ax\rfloor$开始我写了一个真欧几里得来求直线下整点数目,然后由于里头含小数所以不对.于是学习了一下新姿势,思想其实差不多.先把a,b,c同时除以gcd(a,b,c),防止爆int.之后把斜率变成$\frac{bt+c}a-\lfloor\frac{bt+c…
[BZOJ3817/UOJ42]Sum(类欧) 题面 BZOJ UOJ 题解 令\(x=\sqrt r\),那么要求的式子是\[\sum_{d=1}^n(-1)^{[dx]}\] 不难发现,对于每个\(d\)而言的取值只和\([dx]\)的奇偶性相关. 如果\(x\)是个整数,也就是\(r\)是完全平方数的时候,显然是可以直接算答案的. 计算答案的时候显然之和有几个奇数或者几个偶数相关(只要求一个另外一个就是补集) 比如说我们来求有几个是偶数,那么要满足的条件就是\([dx]=2*[\frac{…
传送门 令\(\sqrt r = x\) 考虑将\(-1^{\lfloor d \sqrt r \rfloor}\)魔改一下 它等于\(1-2 \times (\lfloor dx \rfloor \mod 2)\),也就等于\(1 - 2 \times \lfloor dx \rfloor + 4 \times \lfloor \frac{dx}{2} \rfloor\) 那么我们现在就要求\(\sum\limits_{i=1}^n \lfloor ix \rfloor\)的值,求\(\sum…
Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summary> /// 暴力解O(n) /// </summary> /// <param name="nums"></param> /// <param name="target"></param> /// &…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不知道为什么我的常数就是大): #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define File(s) freo…
You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to…