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
上传者
苗栋栋
 #include <stdio.h>
#include <math.h> int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,j,t,n;
int num=;
scanf("%d",&n);
for(i=;i<=sqrt((double)n)+;i++)
{
if((n-i)%(i+)==)
if((n-i)/(i+)>=i)
num++;
}
printf("%d\n",num);
}
return ;
}

优秀代码:

#include<cstring>

#include<cstdio>

#include<map>

#include<string>

#include<algorithm>

#include<vector>

#include<iostream>

#include<cmath>

using namespace std;

#define CLR(arr,val) memset(arr,val,sizeof(arr))

int main()

{

int t,n,cnt=;

//long long num;

int num;

scanf("%d",&t);

while(t--)

{

//  scanf("%lld",&num);

scanf("%d",&num);

int nn=(int)(sqrt(num+1.0)+0.5);

num++;

cnt=;

for(int i=;i<=nn;i++)

if(num%i==) cnt++;

printf("%d\n",cnt);

}

}

简单数学题

nyoj_216_A problem is easy_201312051117的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. putty+Xmanager登陆Linux,实现图形界面操作.

  2. 1章 课程介绍 IDEA介绍演示与安装 IDEA安装

  3. PCB Windows Petya(永恒之蓝)勒索病毒补丁检测代码

    公司内部电脑招受到新的勒索病毒Petya(永恒之蓝)攻击,直接导致受攻击的电脑系统崩贵无法启动,这次勒索病毒攻击影响范围之广,IT,人事,工程,生产,物控等部门都无一幸免,对整个公司运转产生了非常严重 ...

  4. bzoj1433[ZJOI2009]假期的宿舍(匈牙利)

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2544  Solved: 1074 [Submit][St ...

  5. flex中align-content属性

    在flex弹性盒模型中align-content属性控制容器内多行在交叉轴上的排列方式 默认值:stretch 可用值: 属性值:flex-start 属性值:flex-end 属性值:center ...

  6. Kafka详解与总结(一)

    1. Kafka概述 1.1. 消息队列 1)点对点模式(一对一,消费者主动拉取数据,消息收到后消息清除) 点对点模型通常是一个基于拉取或者轮询的消息传送模型,这种模型从队列中请求信息,而不是将消息推 ...

  7. 通过Oracle透明网关连接Sybase

    Oracle公司提出的透明网关技术可用于实现与其他多种类型的数据库的互联,实现不同类型数据之间建立连接,方便于使用者进行查询.近日,在公司的某项目的实施过程中,开发人员需要访问Sybase数据库中的某 ...

  8. 使用yum命令更新时锁住了怎么办?

    出现的状况如下: [root@iZwz951sp834mvbed8gdzzZ ~]# yum update kernelLoaded plugins: fastestmirrorExisting lo ...

  9. [转]android 让一个控件按钮居于底部的几种方法

    本文转自:http://www.cnblogs.com/zdz8207/archive/2012/12/13/2816906.html android 让一个控件按钮居于底部的几种方法 1.采用lin ...

  10. 一个.py引用另一个.py中的方法

    处理函数 X_Add_Y_Func.py #__author__ = 'Administrator' def add_func(x, y): return x+y 调用函数 X_Add_Y_Func_ ...