UVA138 Street Numbers(数论)
题目链接。
题意:
找一个n,和一个m(m < n),求使得1~m的和等于m~n的和,找出10组m,n
分析;
列出来式子就是
m*(m+1)/2 = (n-m+1)*(m+n)/2
化简后为 m*m*2 = n*(n+1)
可以枚举n,然后二分找m,不过这样大约会用10s多,可以打表。
打表程序:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip> using namespace std; typedef unsigned long long int LL; int main() {
freopen("my.txt", "w", stdout);
int cnt = ; for(LL n=; cnt < ; n++) {
LL l = , h = n;
while(l <= h) {
LL mid = (l+h)/;
LL t1 = *mid*mid, t2 = n*(n+);
if(t1 == t2) {
cout << '"' << setw() << mid << setw() << n << '"' << ',';
cnt++;
break;
}
else if(t1 < t2) l = mid+;
else h = mid-;
}
} return ;
}
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; char a[][] = {" 6 8"," 35 49"," 204 288"," 1189 1681"," 6930 9800"," 40391 57121"," 235416 332928",
" 1372105 1940449"," 7997214 11309768"," 46611179 65918161"}; int main() { for(int i=; i<; i++) {
printf("%s\n", a[i]);
}
return ;
}
UVA138 Street Numbers(数论)的更多相关文章
- POJ 1320 Street Numbers 【佩尔方程】
任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- POJ 1320 Street Numbers 解佩尔方程
传送门 Street Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2529 Accepted: 140 ...
- POJ 1320 Street Numbers(佩尔方程)
Street Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3078 Accepted: 1725 De ...
- POJ 1320:Street Numbers
Street Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2753 Accepted: 1530 De ...
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- codeforces 446C DZY Loves Fibonacci Numbers 数论+线段树成段更新
DZY Loves Fibonacci Numbers Time Limit:4000MS Memory Limit:262144KB 64bit IO Format:%I64d &a ...
- POJ 3641 Pseudoprime numbers (数论+快速幂)
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...
- POJ1320 Street Numbers【佩尔方程】
主题链接: http://poj.org/problem?id=1320 题目大意: 求解两个不相等的正整数N.M(N<M),使得 1 + 2 + - + N = (N+1) + - + M.输 ...
随机推荐
- LINUX 内核与 systemtap +GO 专家博客 一个[ 系统软件工程师] 的随手涂鸦
http://nanxiao.me/category/%E3%80%8Anix-hacking%E3%80%8B%E6%9D%82%E5%BF%97/ 月刊 https://github.co ...
- python小练习,打出1-100之间的所有偶数,设计一个函数,在桌面上创建10个文件,并以数字命名,复利计算函数
练习一:打出1-100之间的所有偶数 def even_print(): for i in range(1,101): if i % 2 == 0: print (i) even_print() #列 ...
- python-增删改查
###增删改查 names = ["zhangding","wangxu","wudong","cheng"] #增 n ...
- 排名最重要的三个优化阶段分析 --------------------->>转至(卧牛SEO/武汉SEO http://blog.sina.com.cn/zhengkangseo )
网站排名,不是一两天能够决定的.要想取得好的排名,得分时间分阶段地做排名,网站优化分前期,中期,后期,怎么来区别不同的阶段该用怎样的优化手段.今晚SEO研究中心创始人Moon老师分享:排名最重要的三个 ...
- Linq101-Quantifiers
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Quantif ...
- dom4j 笔记【转】
SAXReader reader = new SAXReader(); Document doc = reader.read(...); List childNodes = doc.selectNod ...
- AutoLayout(转)
转自 http://blog.sina.com.cn/s/blog_9564cb6e0101wv9o.html controller和View的责任分配: 1.View指定固有的content ...
- 使用less函数实现不同背景的CSS样式
今天在公司遇到一个比较特殊的需求,需要完成这样的布局,如下图: 每一个块的背景需要不同,而其他都是相同的,这时候就应该把背景提出来单独写成一个CSS样式类. 那么问题来了,有四个不同的背景需要写4个基 ...
- Hadoop 中 IPC 的源码分析
最近开始看 Hadoop 的一些源码,展开hadoop的源码包,各个组件分得比较清楚,于是开始看一下 IPC 的一些源码. IPC模块,也就是进程间通信模块,如果是在不同的机器上,那就可以理解为 RP ...
- 『重构--改善既有代码的设计』读书笔记----Introduce Explaning Variable
有时候你会遇到一系列复杂的表达式连续运算的时候,这个时候你可能根本招架不住如此长或者是如此复杂的长函数.这个时候你可以通过引用临时变量来储存他们的结果,将这些长函数的结果分成一个个临时变量来让函数清晰 ...