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

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[100005];
int gcd(int a,int b)
{
   return b==0?a:gcd(b,a%b);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        bool ff=0;
        bool f=0;
        int x=2*b-a;
        int y=9*b;

        if(x==0)
        {
            cout<<1<<endl;
            continue;
        }
        else if(x<0||5*x>y)
        {
            cout<<"0"<<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-5*x;
        memset(d,0,sizeof(d));
        for(int i=1;i<=x;i++) d[i]=5;
        int i=1;
        while(y>=4)
        {
            y=y-4;
            d[i]+=4;
            i++;
        }
        x=max(x,i-1);
        if(y)
        {
            d[i]+=y;
            if(x==i-1) x++;
        }
        for(int j=x;j>=1;j--)
            cout<<d[j];
        cout<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/caiyishuai/p/9034149.html

时间: 2024-07-31 23:02:47

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

HDU 5710 digit sum

题意: 定义S(N) 为数字N每个位上数字的和. 在给两个数a,b,求最小的正整数n,使得 a×S(n)=b×S(2n). 分析: 为我们要找到满足 a * S(n) = bS(2n) 的最小的n的值,首先第一个想法肯定暴力啊..但是暴力肯定不对啊... 比如--->2 3 输出5589 也就是说从整体(一个数字)到部分(各个位数)的思路是行不通的,因为是digit 所以可以尝试由部分到整体也就是构造呀. 那么如何构造呢?从若不存在S(2n) 那么我们的构造一定是从低位构造到高位. 但是有S(2

hdu 4710 Balls Rearrangement (数学思维)

题意:就是  把编号从0-n的小球对应放进i%a编号的盒子里,然后又买了新盒子, 现在总共有b个盒子,Bob想把球装进i%b编号的盒子里.求重置的最小花费. 每次移动的花费为y - x ,即移动前后盒子编号的差值的绝对值. 算法: 题目就是要求                  先判断  n与  lcm(a,b)的大小,每一个周期存在循环,这样把区间缩短避免重复计算. 如果n>lcm(a,b)则   ans = (n/lcm)*solve(lcm)+solve(n%lcm) 否则   ans =

Acdreamoj1115(数学思维题)

题意:1,3是完美数,如果a,b是完美数,则2+a*b+2*a+2*b,判断给出的n是否是完美数. 解法:开始只看出来2+a*b+2*a+2*b=(a+2)*(b+2)-2,没推出更多结论,囧.没办法,只能暴力将所有的完美数求出来然后查表.正解是c+2=(a+2)*(b+2);完美数都是有质因子3或5组成的(5本身除外): 自己暴力代码: /****************************************************** * author:xiefubao *****

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

水 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<math.h> 4 #include<iostream> 5 #define LL long long 6 using namespace std; 7 8 int main() 9 { 10 int t; 11 int a,b; 12 int cas; 13 LL sum; 14 while(~scanf("%d",&

HDU - 1003 Max Sum(DP经典题2)

题意:给出一串数,求最大和的字串和起始终点位置. 与导弹问题大同小异,有状态转移方程就很好做了. 状态转移方程:d[i]=(d[i-1]+a[i]>a[i])?d[i-1]+a[i]:a[i]; 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 const int maxn=100000+10; 6 7 int dp[maxn],num[maxn]; 8 9 int main(){ 10

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

Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 --每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2) + b(X) + c = 0 .求X解的个数. 思路: 分别讨论二次方程与一次方程的情况,再特殊处理下 a = b = c = 0 的情况. 感想: 是时候该水水题了. Java AC代码: 1 import java.math.*; 2 import java.util.Scanner; 3

HDU 4972 A simple dynamic programming problem(数学思维题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4972 Problem Description Dragon is watching NBA. He loves James and Miami Heat. Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is

hdu 5430 Reflect (数学推导题)

Problem Description We send a light from one point on a mirror material circle,it reflects N times and return the original point firstly.Your task is calcuate the number of schemes. ![](../../data/images/C628-1004-1.jpg) Input First line contains a s

51Nod 1003 阶乘后面0的数量(数学,思维题)

1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720,720后面有1个0. Input 一个数N(1 <= N <= 10^9) Output 输出0的数量 Input示例 5 Output示例 1题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1003编程之美有讲:一个数 n