Problem E

Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 16   Accepted Submission(s) : 9

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

When Teddy was a child , he was always thinking about some simple math problems ,such as “What it’s 1 cup of water plus 1 pile of dough ..” , “100 yuan buy 100 pig” .etc..

One day Teddy met a old man in his dream , in that dream the man whose name was“RuLai” gave Teddy a problem :

Given an N , can you calculate how many ways to write N as i * j + i + j (0 < i <= j) ?

Teddy found the answer when N was less than 10…but if N get bigger , he found it was too difficult for him to solve.
Well , you clever ACMers ,could you help little Teddy to solve this problem and let him have a good dream ?

Input

The first line contain a T(T <= 2000) . followed by T lines ,each line contain an integer N (0<=N <= 1010).

Output

For each case, output the number of ways in one line.

Sample Input

2
1
3

Sample Output

0
1 易知用两个循环嵌套判断n=i*j+i+j必然超时,可以推得n+1=i*j+i+j+1,即为n+1=(i+1)*(j+1);
题中提示j>=i>0;那么j+1>=i+1,用x代替(i+1),将x从2遍历到sqrt(n+1),在此条件下判断(n+1)%x,若为0,说明
存在(j+1),使得(i+1)*(j+1)=n+1,由于是在(i+1)<=sqrt(n+1)的条件下的结果,必然有(j+1)>=(i+1)成立。
时间复杂度由O(n)变为O(sqrt(n)).

hdoj 2601(判断N=i*j+i+j)的更多相关文章

  1. for循环j = j++ 和 j = ++j

    package com.test.forname; public class TestForName { public static void main(String[] args) throws E ...

  2. 存在使i > j || i <= j不成立的数吗?

    存在使i > j || i <= j不成立的数吗? 咋一看有点晕!一个数既不能大于也不能小于等于另一个数?那是什么数?答案是”非数“ 例子如下:‘ if(Double.NaN>Flo ...

  3. 给出一个数组A,找出一对 (i, j)使得A[i] <= A[j] (i < j)并且j-i最大

    题目:给出一个数组A,找出一对 (i, j)使得A[i] <= A[j] (i <= j)并且j-i最大 ,若有多个这样的位置对,返回i最小的那一对. 最直接的想法就是对于每一个 i 从数 ...

  4. GCD - Extreme (II) for(i=1;i<N;i++) for(j=i+1;j<=N;j++) { G+=gcd(i,j); } 推导分析+欧拉函数

    /** 题目:GCD - Extreme (II) 链接:https://vjudge.net/contest/154246#problem/O 题意: for(i=1;i<N;i++) for ...

  5. j++与++j

    (j++)+(++j)+(++j) 核心部分汇编代码 执行顺序j原始值为5,存放在栈的ebp-4中;q无初始值,存放在栈的ebp-8中先执行一次j自增赋值++j ;j=6执行第一个加法运算;值存放在C ...

  6. jmeter-ERROR o.a.j.p.j.c.DataSourceElement: JDBC data source already defined for: 报错原因

    转载自:https://www.cnblogs.com/zhangfeivip/p/9450403.html Jmeter 多个threadgroup 中的配置元件会一次性进行初始化   例如3个th ...

  7. j$(function() j$(document).ready 区别

    $j(document).ready(function(){}); // 或者  $j(function(){}); 第一个是直接使用Jquery调用function,第二个是在文档加载完毕后才去调用 ...

  8. QAU 18校赛 J题 天平(01背包 判断能否装满)

    问题 J: 天平 时间限制: 1 Sec  内存限制: 128 MB提交: 36  解决: 9[提交][状态][讨论版][命题人:admin] 题目描述 天平的右端放着一件重量为w的物品.现在有n个重 ...

  9. CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...

随机推荐

  1. Maven学习(1) - Maven入门

    home index:http://maven.apache.org/ download:http://maven.apache.org/download.cgi install: http://ma ...

  2. Asp.net 字体样式

    在页面中使用到字体样式  “微软雅黑“,在静态页面中显示正常,但在asp.net页面中字体无效,此时只需把字体修改为“Microsoft YaHei";

  3. Bzoj 2588: Spoj 10628. Count on a tree 主席树,离散化,可持久,倍增LCA

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2588 2588: Spoj 10628. Count on a tree Time Limit ...

  4. octopress添加回到顶部按钮

    准备回到顶部的png图片一枚,可以随自己喜好google.分享我的 取名top.png,保存在octopress/source/images/top.png octopress/source/_inc ...

  5. [转+整理]LINUX学习笔记(1):磁盘结构及分区

    整理自: http://vbird.dic.ksu.edu.tw/linux_basic/0130designlinux_2.php http://lengjianxxxx.blog.163.com/ ...

  6. java 23 种设计模式

    一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...

  7. bzoj 2741 分块+可持久化trie

    多个询问l,r,求所有子区间异或和中最大是多少 强制在线 做法: 分块+可持久化trie 1.对于每块的左端点i,预处理出i到任意一个j,()i,j)间所有子区间异或和中最大为多少,复杂度O(\(n\ ...

  8. November 4th Week 45th Friday 2016

    Problems are not stop signs, they are guidelines. 问题不是休止符,而是指向标. Most of the problems can be overcom ...

  9. Winform 中 DesignMode 返回值不正确的问题。

    本文转载:http://blog.csdn.net/sabty/article/details/5325260 以前也曾遇到这样的问题,不过影响不大也没有去详细了解.今天又重新遇到此问题,实在太不便. ...

  10. Node.js小Httpserver

    须要说明两点: 1 程序文件hello.js需用记事本另存为utf-8格式的hello.js watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamVhcGVk ...