Digit-Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 782    Accepted Submission(s):
241

Problem Description
Let S(N)

be digit-sum of N

, i.e S(109)=10,S(6)=6

.

If two positive integers a,b

are given, find the least positive integer n

satisfying the condition a×S(n)=b×S(2n)

.

If there is no such number then output 0.

 
Input
The first line contains the number of test caces T(T≤10)

.
The next T

lines contain two positive integers a,b(0<a,b<101)

.

 
Output
Output the answer in a new line for each test
case.
 
Sample Input
3
2 1
4 1
3 4
 
Sample Output
1
0
55899
 
Source
 
Recommend
liuyiding

#include<stdio.h>
#include<string.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<time.h>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
int d[];
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d %d",&a,&b);
bool ff=;
bool f=;
int x=*b-a;
int y=*b; if(x==)
{
cout<<<<endl;
continue;
}
else if(x<||*x>y)
{
cout<<""<<endl;
continue;
}
int xx,yy;
xx=max(x,y);
yy=min(x,y);
int pp=gcd(xx,yy);
x=x/pp;
y=y/pp;
y=y-*x;
memset(d,,sizeof(d));
for(int i=;i<=x;i++) d[i]=;
int i=;
while(y>=)
{
y=y-;
d[i]+=;
i++;
}
x=max(x,i-);
if(y)
{
d[i]+=y;
if(x==i-) x++;
}
for(int j=x;j>=;j--)
cout<<d[j];
cout<<endl;
}
return ;
}

2016女生赛 HDU 5710 Digit-Sum(数学,思维题)的更多相关文章

  1. HDU 5710 Digit Sum

    Let S(N)S(N) be digit-sum of NN, i.e S(109)=10,S(6)=6S(109)=10,S(6)=6. If two positive integers a,ba ...

  2. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  3. 2014上海网络赛 HDU 5053 the Sum of Cube

    水 #include <stdio.h> #include <stdlib.h> #include<math.h> #include<iostream> ...

  4. hdu 4710 Balls Rearrangement (数学思维)

    意甲冠军:那是,  从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号 ...

  5. HDU 1840 Equations (简单数学 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 ——每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2 ...

  6. hdu 5430 Reflect (数学推导题)

    Problem Description We send a light from one point on a mirror material circle,it reflects N times a ...

  7. hdu 2710 Max Factor 数学(水题)

    本来是不打算贴这道水题的,自己却WA了三次.. 要考虑1的情况,1的质因子为1 思路:先打表 ,然后根据最大质因子更新结果 代码: #include<iostream> #include& ...

  8. hdu 4091 数学思维题贪心

    /* 参看博客地址:http://blog.csdn.net/oceanlight/article/details/7857713 重点是取完最优的后剩余的rest=n%lcm+lcm;中性价比小的数 ...

  9. 【CSP模拟赛】坏天平(数学&思维)

    蹭兄弟学校的题目做还不用自己出题的感觉是真的爽 题目描述 nodgd有一架快要坏掉的天平,这架天平右边的支架有问题,如果右边的总重量比左边多太多,天平就彻底坏掉了.现在nodgd手上有n种砝码,质量分 ...

随机推荐

  1. MySQL安装配置教程

    环境:Windows 7 旗舰版 64位MySQL版本:mysql-5.5.14-winx64MySQL下载地址:http://dev.mysql.com/downloads/installer/ 1 ...

  2. 排序方法整理Java - 冒泡排序、选择排序、插入排序、快速排序

    /** * 排序方法整理 * @author zhyea * */ public class Sort { /** * 冒泡排序,从小到大. * 冒泡排序是比较相邻的两个元素,若顺序错误,则执行交换. ...

  3. Div层弹出

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  4. zoj3195倍增lca

    求三点之间的最短路,,分别求两点之间的lca除2即可(代码写的太挫了,wa了14发= =) #include<map> #include<set> #include<cm ...

  5. WebService是什么?以及工作原理

    WebService 就是一个应用程序,向外界暴露出公开的API使别人其能在WEB对其进行远程调用,具有跨平台和跨语言的等特点,采用Internet的Http协议进行客户端与服务器之间的交互 由XML ...

  6. 【Hive】建表

    1.建表 Create [EXTERNAL] TABLE [IF NOT EXISTS] table_name ( [(col_name data_type [COMMENT col_comment] ...

  7. 【C#】Socket中的ssl通信

    引言    有个项目中用到了Socket ssl通信,在此记录一下. 证书 Socket ssl需要用到证书用来校验身份,而作为调试,我们只需用测试证书即可. 有个工具可以很方便地制作测试证书,下载地 ...

  8. WPF控件开源资源

    (转)WPF控件开源资源 Textbox Drag/Drop in WPFhttp://www.codeproject.com/Articles/42696/Textbox-Drag-Drop-in- ...

  9. MAC版画图软件 paintbrush 推荐,类似 windows 上系统自带的画图软件

    不想开photoshop这么重的软件,但是对于屏幕截图有需要有一点处理.这时候我想起 windows上画图的好了. 搜索了一下,知道了 paintbrush 这个软件,于是下载试用了一下,果然很好. ...

  10. windows下Perl如何读取大文件的最后一行(总结)

    Perl中读取文件最后一行的方法很多,比如 (1)将文件读入数组,取最后一个元素 open (FILE,"file.txt") or die "$!"; my ...