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. LeftoverDataException,依赖包,apache license 2.0

    1. poi3.9 LeftoverDataException org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: ...

  2. scala学习手记35 - 隐式类型转换

    先来看一下下面的内容: 2 days "ago" 5 days "from_now" 如上的内容具体应该是什么呢?不过怎么看也不像是代码.不过既然是在学代码,拿 ...

  3. pandas 选取数据 修改数据 loc iloc []

    pandas选取数据可以通过 loc iloc  [] 来选取 使用loc选取某几列: user_fans_df = sample_data.loc[:,['uid','fans_count']] 使 ...

  4. [Kafka] - Kafka Java Producer代码实现

    根据业务需要可以使用Kafka提供的Java Producer API进行产生数据,并将产生的数据发送到Kafka对应Topic的对应分区中,入口类为:Producer Kafka的Producer ...

  5. 【疯狂labview】 Xcontrol+LVoop封装练习 Toolbar

    labview没有toolbar,并且没有可复用的 控件 其实项目中很需要 特别是在框架平台的搭建上, 本文以Xcontrol用PICTURE的方式实现toolbar,并用LVoop封装 废话少说 直 ...

  6. redis、kafka、rabittMQ对比 (转)

    本文不对三者之间的性能进行对比,只是从三者的特性上区分他们,并指出三者的不用应用场景. 1.publish/subscribe 发布订阅模式如下图所示可以具有多个生产者和发布者,redis.kafka ...

  7. HDU - 4746预处理莫比乌斯反演

    链接 求[1,n] 和 [1,m]中有多少对数的GCD的素因子个数小于等于p 直接暴力做特定超时,所以我们想办法预处理,对于p大于18(1到5e5的最大素数因子个数)的情况,每一对都满足条件,O(1) ...

  8. 在web.xml中配置spring配置文件的路径

    <context-param>     <param-name>contextConfigLocation</param-name>     <param-v ...

  9. iptables(二)iptables实际操作之规则查询

    如果你是一个新手,在阅读如下文章时,请坚持读到最后,读的过程中可能会有障碍,但是在读完以后,你会发现你已经明白了. 在进行iptables实验时,请务必在测试机上进行. 之前在iptables的概念中 ...

  10. 点击bindingNavigatorAddNewItem 关联的dataGridView不会新增一行

    方法一. 在设计界面,修改bindingNavigator1的属性AddNewItem 为“(无)”: 方法二. 在设计器自动生成的代码中找到这一行:             // bindingNa ...