Digit-Sum HDU
来源:互联网 发布:安卓版本 知乎 编辑:程序博客网 时间:2024/05/17 15:22
Let S(N) be digit-sum of N , i.e S(109)=10,S(6)=6 .
If two positive integersa,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.
If two positive integers
If there is no such number then output 0.
The next
32 14 13 4
1055899
题意很好理解 因为 s(n) 中 各个位数字设 t , t为 1-4 时 放大2倍 为 2t , t 而 5-9时 放大2倍 则变为 2t -9
设 5 -9的个数为L 那么 s(2n)=2s(n)-9L 则 (a-2b)*s(n)=9bL; s(n) / l =9b / (a-2b) 那么 a-2b 是 5-9的个数 9b是 s(n) 这样我们得保证 a-2b >=0 且 9b - 5*( a-2b)>0
我们先假设这 a-2b 个数全为 5 设 p=9b - 5*( a-2b) ;
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>#include<queue>#include<iomanip>#include<bits/stdc++.h>#define eps 1e-8//#define inf 0x7f//int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }using namespace std;int aa[300];int main(){ int t,a,b; scanf("%d",&t); while(t--) { memset(aa,0,sizeof(aa)); scanf("%d%d",&a,&b); int k2=2*b-a; int k1=9*b; if(k2<0||b>5*a) { printf("0\n"); continue; } if(k2==0) { printf("1\n"); continue; } int u=__gcd(k1,k2); k1=k1/u; k2=k2/u; int i; int p=k1-(k2*5); for(i=0;i<k2;i++) { int e=min(4,p); aa[i]=5+e; p=p-e; } while(p) { int e=min(4,p); aa[i++]=e; p=p-e; } for(i=i-1;i>=0;i--) printf("%d",aa[i]); printf("\n"); }}
阅读全文
0 0
- HDU 5710 Digit-Sum
- HDU 5710 Digit-Sum
- Digit-Sum HDU
- HDU 5710 Digit-Sum
- [HDU 5710]Digit-Sum:其他
- Hdu 5710 Digit-Sum【思维】
- HDU 5710 Digit-Sum 数学杂题
- HDU 5710 Digit-Sum (构造)
- lucky sum of digit
- [projecteuler]Factorial digit sum
- Sicily 7969. Digit Sum
- HDU5710-Digit-Sum
- UVALive6497 Digit Sum【贪心】
- cc Minimal Weighted Digit Sum
- Problem 16:Power digit sum
- Problem 20:Factorial digit sum
- Problem 16:Power digit sum
- PE 16 Power digit sum
- 23种设计模式
- 最优化方法
- puppet 简单的安装及配置
- Struts2(六)---OGNL
- 策略模式
- Digit-Sum HDU
- 创建一个简单的ModelValidator
- Qt Project ERROR: Cannot run compiler 'cl'
- android 屏幕保持唤醒 不锁屏 android.permission.WAKE_LOCK
- React Native的环境搭配
- kylin 优化
- jqgrid(使用一)
- Spark Learning(RDD介绍)
- yii查询