//组合数学
//计算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. discuz 和 wordpress 整合注意问题

    要先在应用列表里添加自己本身的应用即要保证同步操作,本身也是一个应用,并保证通信成功: 应用和ucenter不在一个机器上,IP都要设定: discuz/uc_client/ 下要有一个接收数据的da ...

  2. csv内存流文件流

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  3. 从汇编来看c语言之指针

    一.基础研究 将下面的程序编译连接,用debug加载: 首先执行第一条语句: 发现p=(unsigned char *)0x1000;在这里是把1000赋给一个偏移地址为01af.大小为两字节的内存空 ...

  4. Entity Framewor 学习笔记 (include + where)

    如果我们想在子查询做过滤的话应该怎样写呢? IEnumerable<Product> products = db.products.Include(p => p.colors.Whe ...

  5. java疯狂演义----简单java IDE工具

    file:commons package org.crazyit.editor.commons; import org.crazyit.editor.EditorFrame; import org.c ...

  6. QQ音乐的请求

    CEF 3.2357.1291.g47e6d4bChromium 43.0.2357.134OS WindowsWebKit 537.36JavaScript 4.3.61.38Flash User ...

  7. Smarty for foreach 使用

    {for} {for}{forelse}用于创建一个简单的循环. 下面的几种方式都是支持的: {for $var=$start to $end}步长1的简单循环. {for $var=$start t ...

  8. sql语句相关操作

    create user test identified by test default tablespace users temporary tablespace temp quota 3M on u ...

  9. java中的浮点(float)运算

    一.  关于浮点运算,需要说明的几点: 1.  在java中,进行浮点运算并不会处理例外情况,所以,即使除数为0,也不会有例外被抛出; 2.  当运算结果是溢出(Infinity)时,结果为Infin ...

  10. linux mount命令学习

    我们在下面这篇博文中已经有笼统的学习了文件系统的一些相关知识, http://blog.csdn.net/boyxulin1986/article/details/12107113 本篇我们主要是用来 ...