摘要:
#include <iostream>#include <vector>#include <iterator>#include <algorithm>struct Area { Area():x(0), y(0) {} Area(int a, int b):x(a),y(b){} int x,y; bool operator<(const Area &rhs) { return x<rhs.x; } //排序用到 friend ostream& operator<<(ostream &out, co 阅读全文
摘要:
题目:p215 寻找不能被[2,31]中连续两个数整除,但能被其它数整除的数long long GCD(long long a, long long b){ if (b == 0) return a; return GCD(b, a%b);}long long LCM(long long a, long long b){ return a*b/GCD(a,b);}long long FindNumber(){ long long lcm=2; for (int j=2; j<31; j++) { lcm=1; for... 阅读全文
摘要:
对于一个正整数,输出它所有可能的连续自然数之和的算式1+2=34+5=92+3+4=9根据题意,有:s+(s+1)+(s+2)+...+(s+k) = n(k+1)s + (k+1)k/2 = n(k+1)(2s+k)=2ns = (2n/(k+1)-k)/2因为 s, k都是整数,所以应满足2n%(k+1)==0 && (2n/(k+1)-k)%2==0void Print(int n, int s, int k){ printf("%d=",n); for (int i=s; i<=s+k; i++) { if (i==s) print... 阅读全文