2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

时间:2021-09-08 16:05:05

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)2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

be digit-sum of N2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

, i.e S(109)=10,S(6)=62016女生赛 HDU 5710 Digit-Sum(数学,思维题)

.

If two positive integers a,b2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

are given, find the least positive integer n2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

satisfying the condition a×S(n)=b×S(2n)2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

.

If there is no such number then output 0.

Input
The first line contains the number of test caces T(T≤10)2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

.
The next T2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

lines contain two positive integers a,b(0<a,b<101)2016女生赛 HDU 5710 Digit-Sum(数学,思维题)

.

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
2016女生赛 HDU 5710 Digit-Sum(数学,思维题)
#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 ;
}