uva 10994 - Simple Addition
//组合数学
//计算sum{i从右往左数的第一个非0数字,p<=i<=q}。
#include <cstdio>
typedef long long ll; ll sum(ll n)
{
ll ans = , x;
while(n)
{
x = n % ;
n /= ;
ans += (( + x) * x) / + n * ; //当个位在循环的时候,高位的朋友你在干嘛?
}
return ans;
} int main()
{
ll a, b;
while(scanf("%lld%lld", &a, &b), a >= )
{
printf("%lld\n", sum(b) - sum(a - ));
}
return ;
}
题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有。
解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~9划分(只会有这几种情况)。
#include <stdio.h>
#define ll long long
ll ans; ll f(ll x) {
if (x == ) return ;
else if (x % )
return x % ;
else
return f(x / );
} void solve(ll l, ll r) {
if (r - l < ) {
for (int i = l; i <= r; i++)
ans += f(i);
return;
} while (l % ) {
ans += f(l);
l++;
} while (r % ) {
ans += f(r);
r--;
}
ans += * (r - l) / ;
solve(l / , r / );
} int main () {
ll l, r;
while (scanf("%lld%lld", &l, &r), l >= || r >= ) {
ans = ;
solve(l, r);
printf("%lld\n", ans);
}
return ;
}
其實只要看題目推敲一下,大概可以知道其實就是各個數字最低階不是0的數字的總和。
可將題目要加的拆成各個位數來做,每一個位數都要考慮%10和/10的情況要加多少,將這些值全部加起來即可得解。
P.S. 雖然p,q可以在32bits整數下存放,但可沒說總和也可以喔!
#include<iostream>
#include<cstdio>
using namespace std; int main(){
long long p, q;
long long sum; while( scanf( "%lld%lld", &p, &q ) != EOF && !( p < && q < )){
sum = ; while( p || q ){
sum += (q%+p%)*((q%)-(p%)+)/;
sum += (q/-p/)*; if( p% && (p/ || q/) ) p += ;
p /= ;
q /= ;
} printf( "%lld\n", sum );
}
return ;
}
uva 10994 - Simple Addition的更多相关文章
- uva 10994 - Simple Addition(规律)
题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...
- 10994 - Simple Addition(规律)
Problem E Simple Addition Input: Standard Input Output: Standard Output Let’s define a simple recurs ...
- 组合数学第一发 hdu 2451 Simple Addition Expression
hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...
- uva 12253 - Simple Encryption(dfs)
题目链接:uva 12253 - Simple Encryption 题目大意:给定K1.求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用高速幂取模推断结果. #inc ...
- HDU 2451 Simple Addition Expression(组合数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...
- HDU2451:Simple Addition Expression
Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- 【计数】Simple Addition Expression
[来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...
- uva 10014 Simple calculations
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
随机推荐
- UITableView 小节-备
UITableView 让列表自动滑动(定位)到某一行 NSIndexPath*scrollIndexPath = [NSIndexPathindexPathForRow:10inSection:0] ...
- hdu 4535 吉哥系列故事——礼尚往来
http://acm.hdu.edu.cn/showproblem.php?pid=4535 错排公式:a[i]=(i-1)*(a[i-2]+a[i-1]): #include <cstdio& ...
- MYSQL如何导出存储过程和触发器?
今天遇到.. 类似下面的就可以: mysqldump -u root -p -ntd -R nxsc>nxsc_trigger.sql
- jsp中pageEncoding、charset=UTF -8
jsp中pageEncoding.charset=UTF -8" 在JSP/Servlet 中主要有以下几个地方可以设置编码,pageEncoding="UTF-8". ...
- WebApi限制IP地址请求
, ); } } } ? true : false; } ...
- Android ListView特别属性用法
由于这两天在做listView的东西,所以整理出来一些比较特别(不常用)的属性,通过设置这样的属性可以做出更加美观的列表 1.stackFromBottom属性,这只该属性之后你做好的列表就会显示你列 ...
- vimrc 留备份
set encoding=UTF-8 "encode with UTF-8"set backspace=2set nusyn onset ai!syntax enablesynta ...
- zookeeper[4] 安装windows zookeeper,及问题处理
安装步骤: 1.在如下路径下载zookeeper-3.4.7.tar.gz http://mirrors.cnnic.cn/apache/zookeeper/stable/ 2.解压zookeeper ...
- 听说每天都要写随笔,word哥~
今天主要学习了html的基本知识,进制的转换,无序列表,有序列表和表格,都是很基本的东西,然后自己自习了表单. <!DOCTYPE html PUBLIC "-//W3C//DTD X ...
- jTemplates——学习(1)
这里介绍一个基于jQuery开发的模板引擎. jTemplates目前最新的版本是0.7.8,由tPython开发.官方网站:http://jtemplates.tpython.com 两个附件, 一 ...