NYOJ 216 A problem is easy

原创 2015年07月09日 19:39:11

A problem is easy

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
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 ?
输入
The first line contain a T(T <= 2000) . followed by T lines ,each line contain an integer N (0<=N <= 10^11).
输出
For each case, output the number of ways in one line
样例输入
2
1
3
样例输出
0
1
双重循环肯定超时的 直接用一个判断条件能减少时间

i*j+i+j =N 经过观察,可以变形为i*j+i+j+1=N+1,也就是说,可以进一步变形为(i+1)*(j+1)=N+1

所以i从2判断到sqrt(n+1)即可
#include<stdio.h>
main(){
	int n,i;
	scanf("%d",&n);
	while(n--){
		int num,sum=0;
		scanf("%d",&num);
		for(i=2;i*i<=num+1;i++){
			if((num+1)%i==0)
			sum++;
		}
		printf("%d\n",sum);
	}

}


版权声明:转载请注明出处

南阳题目216-A problem is easy

A problem is easy 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 When Teddy was a child , he was al...

Adjusting Chinese New Year Effects in R is Easy

(This article was first published on  usefulr » R, and kindly contributed to R-bloggers)      The S...

An Easy Problem?!(poj2826线段相交,直线线段相交)

题意:给你两个同样长的木板,围城一个多边形,水从空中垂直下落,问木板能盛放多少体积的水。 思路:分类讨论 1.如果线段没有交点,那么面积就是0 2.如果线段有交点,但是有一个模板被另一个木板覆盖还是接...

UVA - 11991 - Easy Problem from Rujia Liu? (STL)

UVA - 11991 Easy Problem from Rujia Liu? Time Limit: 1000MS   Memory Limit: Unknown  ...

UVA11991:Easy Problem from Rujia Liu?(STL构建变长二维数组)

11991 Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for exa...

poj-2826 An Easy Problem?!

题意: 给出平面上的两条线段,现在有竖直下落的雨; 求这两条线段最多能接到多少雨; 题解: 听起来挺朴实的一道题,但是并不怎么好做,因为计算几何的实数。。 实际上可以把这道题分为两个...

poj2826 An Easy Problem?!

An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9916 ...
  • modiz
  • modiz
  • 2015年03月10日 19:18
  • 313

POJ 2826 An Easy Problem?! 好题

题目大意就是两根木块组成一个槽,问槽里能装多少雨水,注意雨水垂直落下,思路也很简单,就是分类讨论有点糟。 1.如果两条线段不相交或者平行,则装0; 2.有一条平行x轴,装0; 3.若上面覆盖下面...

hdu5572An Easy Physics Problem+计算几何

An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java...

Easy Problem from Rujia Liu?(map+vector用法)

题意:输入n个数,m组询问,每组询问包含两个整数k,v,询问整数v第k次出现的位置... STL果然神奇~本来准备二维数组搞定,写了一半发现数组太大开不了,就又想到STL的map,然后还是行不通,到网...
  • modiz
  • modiz
  • 2013年05月14日 15:19
  • 593
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:NYOJ 216 A problem is easy
举报原因:
原因补充:

(最多只允许输入30个字)