求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
来源:互联网 发布:淘宝开店钱盾认证 编辑:程序博客网 时间:2024/05/18 03:44
题目来源: http://ac.jobdu.com/problem.php?pid=1506
- 题目描述:
求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 输入:
输入可能包含多个测试样例。
对于每个测试案例,输入为一个整数n(1<= n<=100000)。- 输出:
对应每个测试案例,
输出1+2+3+…+n的值。- 样例输入:
35
- 样例输出:
615
//java
public static long multi(int n, int m){long result = 0;long temp = 0;boolean flag = (m&1)==1;boolean test;test=flag && ((result+=m) > 0)&&((n -= 1)>0);test=( n > 0) && ((m <<=1) > 0);
n >>= 1;
test=( n > 0) && (temp=multi(n, m)) != 0;return result+temp;}public static void main(String[] args) {Scanner scan = new Scanner(System.in);while(scan.hasNextInt()){int n=scan.nextInt();long answer = multi(n,n+1);answer >>=1 ;System.out.println(answer);}scan.close();}
</pre><pre class="java" style="white-space: pre-wrap;" name="code"><span id="_xhe_cursor">typedef unsigned long long UINT64;</span>
UINT64 multi(UINT64 n, UINT64 m, UINT64 *p){ ((n&1) == 1)&& ((*p +=m) && (n -= 1)); (n >0)&& ((m<<=1));
(n >>=1); (n>0) && multi(n,m,p); return (*p);}
int main(){ int n; while(cin >> n) { UINT64 pathCount=0; multi(n,n+1,&pathCount); pathCount >>=1; cout << pathCount << endl; } return 0;}
0 0
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。Java实现
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 题目:求1+2+...+n,要求不能使用乘除法,for,while,if,else,switch,case等关键字及条件判断语句(A?B:C)
- 题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。
- Android解析中国天气网的Json数据
- Linux中断浅析http://bbs.chinaunix.net/thread-3566316-1-1.html
- 进程间通信2
- UVA - 11986 Save from Radiation
- Ubuntu频繁报错
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- JavaScript省市二级联动
- HDU 4406 GPA(网络流-最大费用流)
- 两个页面之间传参数(包括单例模式,sugue,tableView,代理模式)
- POJ 2255 Tree Recovery(二叉树)
- 通过 WPF 强制执行复杂的业务数据规则
- baby step giant step
- poj 2549 --- 传说中的用“桶”防止HASH冲突
- 【BNU Summer Training 2014.08.11】 Nested Segments (线段树,离散化)