Description

这个世界太无聊了,于是God Wang想出了新的运算符号$,对于两个数x,y来说x$y的值等于x和y各个位置上的数字乘积之和,没有的位按0来算

比如说123$321=1*3+2*2+3*1=10,105$51=1*0+0*5+5*1=5。于是God Wang又有了新的问题,

他定义了函数F(L,R)=(((((L$(L+1))$(L+2))$(L+3)....)$R),他想要知道F(L,R)的值,现在请你来告诉他吧。

Input

输入第一行为一个正整数T(T<=1000)

接下来T行,每行两个整数L,R (0<=L<R<=2^31-1)

Output

输出T行,每行一个整数表示输出的答案

Sample Input

3
8 10
50 51
51 64

Sample Output

7
25
38

暴力跑,遇到是0了就退出循环,因为之后一定都是0。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int L,R;
int X[];
int Y[];
int xx,yy; int F(int x,int y)
{
memset(X,,sizeof(X));
memset(Y,,sizeof(Y));
xx=;
yy=;
int ans=;
while(x)
{
X[xx]=x%;
x=x/;
xx++;
}
while(y)
{
Y[yy]=y%;
y=y/;
yy++;
}
for(int i=; i<max(xx,yy); i++)
ans=ans+X[i]*Y[i];
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&L,&R);
int A=L;
for(int i=L+; i<=R; i++)
{
A=F(A,i);
if(A==) break;
}
printf("%d\n",A);
}
return ;
}

ZUFE OJ 2289 God Wang II的更多相关文章

  1. ZUFE OJ 2288 God Wang I

    Description God Wang 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GodW变换 对于一个数字n,该变换后的值GodW(n)为,先令X=n 第一步,如果X为个位数,G ...

  2. 【LeetCode OJ】Path Sum II

    Problem Link: http://oj.leetcode.com/problems/path-sum-ii/ The basic idea here is same to that of Pa ...

  3. 【LeetCode OJ】Word Ladder II

    Problem Link: http://oj.leetcode.com/problems/word-ladder-ii/ Basically, this problem is same to Wor ...

  4. 【LeetCode OJ】Palindrome Partitioning II

    Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning-ii/ We solve this problem by u ...

  5. 【LEETCODE OJ】Single Number II

    Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Nu ...

  6. 【LeetCode OJ】Word Break II

    Problem link: http://oj.leetcode.com/problems/word-break-ii/ This problem is some extension of the w ...

  7. ZUFE OJ 2301 GW I (3)

    Description GW 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GW变换 对于一个数字n,该变换后的值GW(n)为,先令X=n 第一步,如果X为个位数,GW(n)=X,否则执 ...

  8. LeetCode OJ——Pascal's Triangle II

    http://oj.leetcode.com/problems/pascals-triangle-ii/ 杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algo ...

  9. [LeetCode OJ] Linked List Cycle II—Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

随机推荐

  1. win8,win10安装mysql

    以管理员身份进到命令窗口后,找到要安装的文件,执行msiexec /package mysql-installer-community-5.7.16.0.msi   回车即可

  2. iOS 解决文本(uitextfield/uitextView)在中间显示而不在顶部显示 问题

    在对应的控制器中设置下面属性 self.automaticallyAdjustsScrollViewInsets = NO; 这样就好了.

  3. Maven项目下WEB-INFO目录下没有编译的classes文件

    建立mavan项目之后,在项目目录中没有发现编译的classes文件夹 解决办法: 因为maven是默认将编译后的classes文件存入项目下的target文件夹中,所以我们需要修改编译后存放的路径, ...

  4. Openlayer 3 删除上一次绘制的图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. loadrunner破解方法--lm70.dll,mlr5lprg.dll下载地址

    一.由于在压力测试执行中,出现一个-10803的错误 ,为解决这个错误,重新设置的环境变量,在次执行错误,这个问题解决了,但另外一个问题出来了,LR,打开脚本编辑器老提示找不到TEMP目录,当时没有想 ...

  6. history对象 back() forward() go() 和pushState() replaceState()

    History(Window.history对象)对象保存着用户上网的历史记录.处于安全方面的考虑,开发人员无法得知用户浏览过的URL,但是借由用户访问过的页面列表,同样可以在不知道实际URL的情况下 ...

  7. form表单直接传文件

    <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...

  8. GitHub常见错误解决办法

    如果輸入$ git remote add origin git@github.com:djqiang(github帳號名)/gitdemo(項目名).git 提示出錯信息:fatal: remote ...

  9. Javaweb 第6天JDBC课程

    JDBC课程 两日大纲 ● JDBC基本操作 ● 预设语句对象 ● 自定义数据库工具类 ● JDBC批处理 ● 事务 ● 连接池 *********************************** ...

  10. Jmeter 多台机器产生负载

    使用多台机器产生负载的操作步骤如下: (1)在所有期望运行jmeter作为 负载生成器的机器上安装jmeter, 并确定其中一台机器作为 controller ,其他的的机器作为agent .然后运行 ...