friend(hdoj 1719)
Friend
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2207 Accepted Submission(s): 1108
(1) numbers 1 and 2 are friend number;
(2) if a and b are friend numbers, so is ab+a+b;
(3) only the numbers defined in (1) and (2) are friend number.
Now your task is to judge whether an integer is a friend number.
3 13121 12131
YES! YES! NO!
- /*刚刚看到这道题的时候一心只想着打表,但是试了几次都超时,没想到有这种规律....
- c=ab+b+a=b(a+1)+b=(b+1)(a+1)-1,c+1=(b+1)(a+1),所以输入的数加一之后,它只要是2或者3的倍数就可以*/
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- int n;
- while(scanf("%d",&n)!=EOF)
- {
- if(n<1)
- {
- printf("NO!\n");
- }
- else
- {
- n=n+1;
- while(n%2==0)
- n=n/2;
- while(n%3==0)
- n=n/3;
- if(n==1)
- printf("YES!\n");
- else printf("NO!\n");
- }
- }
- }
friend(hdoj 1719)的更多相关文章
- 最小生成树(HDOJ 1863)
畅通工程 http://acm.hdu.edu.cn/showproblem.php?pid=1863 1.Prim算法: Prim算法是由一个点(最初的集合)向外延伸,找到与集合相连权值最小的边, ...
- 射击比赛 (POJ 1719) 题解
[问题描述] 我们假设射击的目标是一个由R*C(2≤R≤C≤ 1000)个小方格组成的矩形网格.网格中每一列恰有2个白色的小方格和R-2个黑色的小方格.定义网格的行从顶至底编号为1~R,列从左至右编号 ...
- 并查集(HDOJ 1856)
并查集 英文:Disjoint Set,即“不相交集合” 将编号分别为1…N的N个对象划分为不相交集合, 在每个集合中,选择其中某个元素代表所在集合. 常见两种操作: n 合并两个集合 ...
- Elevator(hdoj 1008)
Problem Description The highest building in our city has only one elevator. A request list is made u ...
- 【HDOJ 2255】奔小康赚大钱(KM算法)
[HDOJ 2255]奔小康赚大钱(KM算法) 奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDOJ 1716 排列2(next_permutation函数)
Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡 ...
- HDOJ 1028 Ignatius and the Princess III(递推)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- HDOJ 1014 Uniform Generator(公约数问题)
Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...
- HDOJ 1166 敌兵布阵 (线段树)
题目: Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Ti ...
随机推荐
- Ajax 传递json字符串到客户端时报 Internal server error
架构:struts2+JQuery 需求:就是前台请求后台,后台查询数据库,将数据转换成json格式,使用struts2框架赋值给action内的变量jsonStr,前台通过 response.jso ...
- JQuery 兼容所有浏览器的复制到剪切板功能
灵机一动想的点子,应该不难理解 <textarea onmousedown='selectAll(this);'>11111</textarea> function selec ...
- 精确获取对象的类型:Object.prototype.toString()
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
- Android 概览屏幕
文章照搬过来的:原文地址https://developer.android.google.cn/guide/components/recents.html 概览屏幕(也称为最新动态屏幕.最近任务列表或 ...
- ajax-工作原理,包含技术,缺陷
1:原理 2:包含技术 3:缺陷
- google浏览器 打印A4 最大宽度和高度px
width: 1563px;(max) + = 分页了 + = 分页了 + = 没有分页 / ViewBag.results[].Count)); <td width="15%&quo ...
- Golang实现常用排序算法
主函数package main import ( "fmt" "math/rand" "sort" "time") co ...
- Spring Cloud Alibaba、Spring Boot、Spring Cloud对应版本关系
Spring Boot Spring Cloud Spring Cloud Alibaba 2.1.x Greenwich 0.9.x 2.0.x Finchley 0.2.x 1.5.x Edgwa ...
- eas之单据转换规则
/** * BOTP单据转换 * @param botpNum 转换规则编号 * @param BillInfo 原单据 */ public static void BOTP(String b ...
- PIPE、SIGNAL(day11)
一.管道 管道分为两种: 无名管道 有名管道 无名管道用于具有亲缘关系的进程间通讯.无名管道是单工的. 有内核管理的一块内存空间. 使用管道,系统提供了pipe() #include <unis ...