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. 客户端JavaScript基础 网页上的输入输出

    创建: 2017/10/06 完成: 2017/10/07   更新: 2017/10/15 增加了通过事件监听器登陆事件的方法的链接   # TODO: 补充 基于Canvas的图象 客户端Java ...

  2. codevs1004四子连棋

    1004 四子连棋  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白 ...

  3. vue-video-player视频播放插件

    安装依赖 npm install vue-video-player -S 引入配置 //main.js import 'video.js/dist/video-js.css' import 'vue- ...

  4. mysql多表查询 查询排序

    有 ask 问题表  和 answer回答表  回答表中的ask_id和 ask表中的id对应 1.查询 /*查询回答了的 */select a.id,a.title,count(b.ask_id) ...

  5. 【百度之星】-IP聚合

    问题描述: Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个 ...

  6. 高级Java知识

    高级Java知识(JVM.字节码.内存模型) 内存=方法区+栈空间+堆+程序计数器 栈(stack)包括虚拟机栈(VM stack)和本地方法栈(native method stack). 方法区(m ...

  7. C#——设置开机启动

    将exe应用程序设置为开机启动,有多种方法,我们主要通过注册表设置开机启动选项. using Microsoft.Win32; using System.Windows.Forms; static v ...

  8. 在python中调用js或者nodejs

    在python中调用js或者nodejs要使用PyExecJs第三方包. pip install pyexecjs 示例代码 >>> import execjs >>&g ...

  9. How an SSL connection is established

    An SSL connection between a client and server is set up by a handshake, the goals of which are: To s ...

  10. Django中图片的上传并显示

    一.settings配置文件中配置 MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'medias').replace('\\', ...