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. jeesite自定义主题

    jeesite cms首页太丑不够逼格,然而国内有很多高大上的皮肤供你选择,那么本文就一步一步教你如何定制自己的CMS站点视图. 1.下载 jeesite 源码,并安装配置成功 2.进入jeesite ...

  2. tinymce 富文本编辑器 编写资料

    tinymce官方文档: 粘贴图片插件 博客搬运地址 使用Blob获取图片并二进制显示实例页面 tinymce自动调整插件 是时候掌握一个富文本编辑器了——TinyMCE(1) XMLHttpRequ ...

  3. ArgumentError: You need to supply at least one validatio

    创建: 2017/10/02   意思: validate没有内容 例:   validates :title

  4. Android基础整理

     1.使用Debug方式调试程序 2.使用LogCat方式调试程序  3.使用Toast动态显示信息 4.使用AlertDialog实现提示框.. 5.使用OptionsMenu实现选项菜单

  5. [Swift通天遁地]四、网络和线程-(5)解析网络请求数据:String(字符串)、Data(二进制数据)和JSON数据

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. B-Tree 漫谈 (从二叉树到二叉搜索树到平衡树到红黑树到B树到B+树到B*树)

    关于B树的学习还是需要做点笔记. B树是为磁盘或者其他直接存取辅助存储设备而设计的一种平衡查找树.B树与红黑树的不同在于,B树可以有很多子女,从几个到几千个.比如一个分支因子为1001,高度为2的B树 ...

  7. Android 串口驱动和应用测试

    这篇博客主要是通过一个简单的例子来了解Android的串口驱动和应用,为方便后续对Android串口服务和USB虚拟串口服务的了解.这个例子中,参考了<Linux Device Drivers& ...

  8. node(koa)微信公众号接口认证

    使用微信测试号, 花生壳内网穿透 需要注意 token 两边都是自定义, 需要保持一致, const Koa = require('koa') const sha1 = require('sha1') ...

  9. 控制台——EventLog实现事件日志操作

    我们应该如何通过写代码的方式向其中添加“日志”呢? 在操作之前,先明确几个概念: 1:事件日志名(logName):“事件查看器”中的每一项,如“应用程序”.“Internet Explorer”.“ ...

  10. DOM对象之window

    window的属性 top:返回当前窗口的最顶层的先辈窗口 document:返回HTML文档对象 location:当前窗口的地址 self:返回对自身窗口的引用 parent:返回父窗口 如何引用 ...