原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; 求出sum奇因子的个数 就是答案  用算术基本定理的代码求就好了  vis设置为bool的 要不会翻车.. 答案要减一 因为1不是奇数 #include <iostream> #include <cstdio> #include <sstream> #include <…
Sum of Consecutive Integers 题目链接 题意 问N能够分解成多少种不同的连续数的和. 思路 连续数是一个等差数列:$$ \frac{(2a1 + n -1)n}{2} = T$$ 那么\(\frac{2*T}{n}-n = 2*a1-1\),所以当\(n\)为\(T\)的奇因子的时候符合要求. 那么当\(n\)为偶数的时候\(\frac{2*T}{n}-(n-1) = 2*a1\);因为\((n-1)\)为奇数,\(2*a1\)为偶数,所以\(\frac{2T}{n}\…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1278 题意:给你一个数n(n<=10^14),然后问n能用几个连续的数表示; 例如: 15 = 7+8 = 4+5+6 = 1+2+3+4+5,所以15对应的答案是3,有三种; 我们现在相当于已知等差数列的和sum = n, 另首项为a1,共有m项,那么am = a1+m-1: sum = m*(a1+a1+m-1)/2  -----> a1 = sum/m - (m-1)/2 a…
http://www.lightoj.com/volume_showproblem.php?problem=1278 题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种. 思路:先列式子\(N=a+(a+1)+(a+2)+ ...+(a+k-1)=\frac{k·(2a+k-1)}{2} \) 继续化成\(2a-1=\frac{2N}{k} - k \) 可由左式得知,2a-1必为奇数,那么右式必定是一奇一偶,且都为2N的因子.所以只要分解因子记录个数,最后组合求一下即可.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6128 题意:给你n个数,问你有多少对i,j,满足i<j,并且1/(ai+aj)=1/ai+1/aj 在%p意义下. 解法:官方题解说是用二次剩余来解,但是我并不会这玩意了.在网上看到一位大佬没有二次剩余直接通过推公式做出了这题,真是神奇.http://www.cnblogs.com/bin-gege/p/7367337.html  将式子通分化简后可得(ai2+aj2+ai*aj)%p=0 .然后两…
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…
原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 题解: 两个数79和16 相加,不考虑进位相加得85, 只考虑进位进位是10, 85+10 = 95…
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive intege…
POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representati…
题目描述: 不用+,-求两个数的和 原文描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 方法一:用位运算模拟加法 思路1: 异或又被称其为"模2加法" 设置变量recipe模拟进位数字,模拟加法的实现过程 代码: public class Solutio…
推公式的能力需要锻炼.. /* dp的时候要存结构体 里面三个元素: cnt,就是满足条件的个数 sum1,就是满足条件的数字和 sum2,满足条件的数字平方和 推导过程:还是用记忆化搜索模板 dp[pos][mod1][mod2]:后pos位模7=mod1,数位和模7=mod2的状态 设当前状态cur 枚举当前位i,碰到7跳过 求出后pos-1位的状态nxt 这里需要建立当前数的模型: 设x是后pos-1位的数:i*10^len+x; cur.cnt+=nxt.cnt; cur.sum1+=n…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25225   Accepted: 13757 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28929   Accepted: 15525 Description Some positive integers can be represented by a sum of one or more consecutive prime numbe…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697   Accepted: 10800 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
                                                                                                         Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24498   Accepted: 13326 Description Some positive i…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895   Accepted: 10906 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
题意:给一个向量W={w1,w2……,wn},和一个向量B,B的分量只能为1和-1.求||W-αB||²的最小值. 思路:一来一直在想距离的问题,想怎么改变每一维的值才能使这个向量的长度最小,最后无果. 看了题解说是推公式,并且将结果看作是方差,这样W中的负值可直接转化为正值,也即将B所有分量当作1(这里需要想一下),所以只需要看α,当结果为方差时最小,也即α为均值,根据||x||=√∑xi²,将平方项展开,观察思考一下应该可以化解为(n∑wi²-sum²)/n #include<iostrea…
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…
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20020   Accepted: 10966 Description Some positive integers can be represented by a sum of one or more consecutive…
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22019 Accepted: 12051 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations d…
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. Credits:Special thanks to @fujiaozhu for adding this problem and creating all test cases. 这道题是CareerCup上的一道原题,难道…
下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take t…
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 题目要求:计算两个整型的和,但是不能用+和- 我们知道a+b为((a&b)<<1)+(a^b),因此可以用递归的方法 class Solution { public: int getSum(int a, int b)…
在一个D维空间,只有整点,点的每个维度的值是0~n-1 .现每秒生成D条线段,第i条线段与第i维度的轴平行.问D条线段的相交期望. 生成线段[a1,a2]的方法(假设该线段为第i条,即与第i维度的轴平行)为,i!=j时,a1[j]=a2[j],且随机取区间[0,n-1]内的整数.然后a1[i],a2[i]在保证a1[i]<a2[i]的前提下同样随机. 由于D条线段各自跟自己维度的轴平行,我们可以转换成只求第i个维度与第j个维度的相交期望,然后乘以C(2,n)就好了 显然线段[a1,a2]和线段[…
其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒)四五次才上来写这份有抄袭嫌疑的题解... 这2题很类似,多校的rating相当于强化版,不过原理都一样.好像是可以用高斯消元做,但我不会.默默推公式了. 公式推导参考http://www.cnblogs.com/chanme/p/3861766.html#2993306 http://www.cn…
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 一般步骤: 1.计算不用进位的位置,使用异或 2.计算进位,算数与操作,计算完后左一一位 3.如此循环 class Solution { public: int getSum(int a, int b) { int carry…
题意:给n个‘M'形,问最多能把平面分成多少区域 解法:推公式 : f(n) = 4n(4n+1)/2 - 9n + 1 = (8n+1)(n-1)+2 前面部分有可能超long long,所以要转化一下,令a = 8n+1, b = n-1,将两个数都化为a1*10^8+b1的形式,则 (a1*10^8+b1)(a2*10^8+b2) =(a1a2*10^8 + a1b2 + a2b1)*10^8 + b1b2 + 2,由于a1,a2最多2为10^4左右,中间的数就都不会超过long long…
问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 问题分析: 首先我们可以分析人们是如何做十进制的加法的,比如是如何得出5+17=22这个结果的.实际上,我们可以分成三步的:第一步只做各位相加不进位,此时相加的结果是12(个位数5和7相加不要进位是2,十位数0和…
问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高位数字不为0. 因此,符合我们定义的最小的有趣的数是2013.除此以外,4位的有趣的数还有两个:2031和2301. 请计算恰好有n位的有趣的数的个数.由于答案可能非常大,只需要输出答案除以1000000007的余数. 输入格式 输入只有一行,包括恰好一个正整数n (4 ≤ n ≤ 1000). 输…
alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 注意:不能使用运算符喽 那我们采用异或移位操作 public class Solution { public int getSum(int a, int b) { int sum=0,carry=0; do{ sum=a^b;…