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. TCP_AIO_Server_ZC_01

    ZC: 这个例子是,1个skt 投递 1个未决的接收操作 1.package aio.Client; 1.1.这是一个 测试的客户端的代码: package aio.Client; import ja ...

  2. LeetCode第[3]题(Java):Longest Substring Without Repeating Characters 标签:Linked List

    题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: Given a string, find the length of the longest substring without ...

  3. ng2 学习笔记(二)表单及表单验证

    在上一篇文章中提到了表单,只说了表单的数据绑定,这一篇文章主要讲一下表单验证,为什么把表单单独拿出来学习,主要是因为,表单是商业应用的支柱,我们用它来执行登录.求助.下单.预订机票.安排会议,以及不计 ...

  4. php 后台接受POST值

    [场景描述]:展示型企业站制作管理后台,前端框架:vue.js2.0,bootstrap,后台语言:php [问题描述]:使用管理后台向接口发送请求时,接口使用PHP的$_POST['args'],接 ...

  5. 查询相应的key

    一.key pattern 查询相应的key (1)redis允许模糊查询key 有3个通配符  *.?.[] (2)randomkey:返回随机key (3)type key:返回key存储的类型 ...

  6. CodeForces - 197D

    开场连wa三发A题,差点心态崩了,还好坚持打完了,一共A了三题 A题,判断能不能放第一个圆,能放的话,先手比赢 #include<map> #include<set> #inc ...

  7. java 多媒体发送邮件

    import java.util.Properties; import javax.mail.Address; import javax.mail.BodyPart; import javax.mai ...

  8. DDOS工具合集---CC 2.0(僵尸网络proxy,单一url,可设置cookie,refer),传奇克星(代理+单一url,可设置cookie),NetBot_Attacker网络僵尸1.0(僵尸网络,HTTP NO-Cache Get攻击模式,CC攻击,HTTP空GET请求攻击),傀儡僵尸VIP1.4版(僵尸网络,动态单一url)、上兴网络僵尸2.3、中国制造网络僵尸、安全基地网络僵尸==

    DDOS工具合集 from:https://blog.csdn.net/chinafe/article/details/74928587 CC 著名的DDOS CC工具,效果非常好!CC 2.0使用了 ...

  9. GAN的原理入门

    开发者自述:我是这样学习 GAN 的 from:https://www.leiphone.com/news/201707/1JEkcUZI1leAFq5L.html   Generative Adve ...

  10. 如何切换到自定义的Activity

    一. 新建一个空的工程,并添加一个按钮 二.新建一个布局文件,命名为my_aty, 并添加一个文本 三.新建一个类,命名为MyAty,并重写onCreate函数 public void onCreat ...