题目链接

题意:

找一个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(数论)的更多相关文章

  1. POJ 1320 Street Numbers 【佩尔方程】

    任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  2. POJ 1320 Street Numbers 解佩尔方程

    传送门 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2529   Accepted: 140 ...

  3. POJ 1320 Street Numbers(佩尔方程)

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3078   Accepted: 1725 De ...

  4. POJ 1320:Street Numbers

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2753   Accepted: 1530 De ...

  5. UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

      Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people e ...

  6. UVA 10539 - Almost Prime Numbers(数论)

    UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...

  7. codeforces 446C DZY Loves Fibonacci Numbers 数论+线段树成段更新

    DZY Loves Fibonacci Numbers Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  8. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

  9. POJ1320 Street Numbers【佩尔方程】

    主题链接: http://poj.org/problem?id=1320 题目大意: 求解两个不相等的正整数N.M(N<M),使得 1 + 2 + - + N = (N+1) + - + M.输 ...

随机推荐

  1. C primer plus 读书笔记第十章

    这一章的标题是数组和指针.指针是C语言的精髓所在,而数组的概念和指针又息息相关,所以放在一起讲. 1.数组 主要内容有:1.1.数组初始化.1.2.指定初始化.1.3.数组赋值.1.4.数组边界.1. ...

  2. spring mvc使用ClassPathXmlApplicationContext或FileSystemXmlApplicationContext和XmlWebApplicationContext类的操作其中 XmlWebApplicationContext是专为Web工程定制的。

    一.简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例(对象).可以用: ApplicationContext ac = new ClassPathXmlAp ...

  3. Linux &amp; Mac curl 命令行使用——POST&amp;GET

    http提交一个表单,比較经常使用的是POST模式和GET模式 在curl的命令行下,GET模式什么option都不用.仅仅须要把变量写在url里面就能够了 比方: curl http://www.s ...

  4. javascript 鼠標拖動功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. sizeof操作符-结构体与类大小

    导读 sizeof是C/C++一个难点,当在自定义类上应用sizeof操作符时,总会出现意想不到的结果,下面,我们就来探讨一下sizeof这个操作符! 目录 1. sizeof与strlen的区别 2 ...

  6. Python开发【第九篇】:HTML (二)

    python[第十四篇]HTML基础 时间:2016-08-08 20:57:27      阅读:49      评论:0      收藏:0      [点我收藏+] 标签: 什么是HTML? H ...

  7. AndroidStudio SDK版本下载

    错误描述: pkg: /data/local/tmp/com.example.myapplication Failure [INSTALL_FAILED_OLDER_SDK] 出现这个错误,研究了半天 ...

  8. IE8 placeholder兼容+Password兼容

    对于placeholder兼容问题 IE系列的大部分不兼容 使用JQ插件解决这个问题,确实用法很简单 jS下载地址http://www.ijquery.cn/js/jquery.placeholder ...

  9. MySQL DELETE

    MySQL DELETE 语句 你可以使用 SQL 的 DELETE FROM 命令来删除 MySQL 数据表中的记录. 你可以在mysql>命令提示符或PHP脚本中执行该命令. 语法 以下是S ...

  10. 【BZOJ1010】玩具装箱

    Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...