//组合数学
//计算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的更多相关文章

  1. uva 10994 - Simple Addition(规律)

    题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...

  2. 10994 - Simple Addition(规律)

    Problem E Simple Addition Input: Standard Input Output: Standard Output Let’s define a simple recurs ...

  3. 组合数学第一发 hdu 2451 Simple Addition Expression

    hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...

  4. uva 12253 - Simple Encryption(dfs)

    题目链接:uva 12253 - Simple Encryption 题目大意:给定K1.求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用高速幂取模推断结果. #inc ...

  5. HDU 2451 Simple Addition Expression(组合数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...

  6. HDU2451:Simple Addition Expression

    Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...

  7. UVA - 10014 - Simple calculations (经典的数学推导题!!)

    UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  8. 【计数】Simple Addition Expression

    [来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...

  9. uva 10014 Simple calculations

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. DEDE提高生成HTmL的速度

    1.找到include/inc/inc_fun_SpGetArcList.php打开之.   2.查找以下代码:   for($i=0;$i<$ridnum;$i++){     if($tps ...

  2. 用dup2和dup产生一份file descriptor 的拷贝

    在类Unix操作系统里面,.dup2和dup都通过系统调用来产生一份file descriptor 的拷贝.   dup对我来说还很简单   int dup(int filedes);   dup2就 ...

  3. Mac下安装MySQL-python

    前提系统中已安装python.mysql数据库: 第一步(终端输入): $ export PATH=$PATH:/usr/local/mysql/bin 第二步(终端输入): $ sudo pip i ...

  4. 开发H5小游戏

    Egret白鹭H5小游戏开发入门(一)   前言: 好久没更新博客了,以前很多都不会,所以常常写博客总结,倒是现在有点点经验了就懒了.在过去的几个月里,在canvas游戏框架方面,撸过了CreateJ ...

  5. android更新SDK时候丢失annotations.jar 导致支持库报错

    I am trying to update my Android SDK Tools to 17 rev. and I updated usign SDK Tools but in Propertie ...

  6. ural 1294 Mars Satellites

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...

  7. row cache lock

    SQL> col name format a30 SQL> select * from (select SAMPLE_TIME, SESSION_ID, NAME, P1, P2, P3, ...

  8. centos6.5+Django+mysql+nginx+uwsgi

    centos6.5+Django+mysql+nginx+uwsgi 1.nginx的安装.这里采用nginx-1.6.0, 建立一个shell脚本然后执行. #!/bin/bash nginx_ve ...

  9. eclipse 解决插件失效

    昨天系统崩溃,重装系统后eclipse突然对links方式加载插件失效.用尽了网上各种解决方法,始终不行.在%eclispe_dir%/configration/org.eclipse.update/ ...

  10. Mac OS X下HomeBrew安装卸载

    1.卸载 cd `brew --prefix` rm -rf Cellar brew prune rm `git ls-files` rm -r Library/Homebrew Library/Al ...