博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj3662Math Magic
阅读量:6124 次
发布时间:2019-06-21

本文共 2421 字,大约阅读时间需要 8 分钟。

Math Magic

Time Limit: 3 Seconds      
Memory Limit: 32768 KB

Yesterday, my teacher taught us about math: +, -, *, /, GCD, LCM... As you know, LCM (Least common multiple) of two positive numbers can be solved easily because of a * b = GCD (a, b) * LCM (a, b).

In class, I raised a new idea: "how to calculate the LCM of K numbers". It's also an easy problem indeed, which only cost me 1 minute to solve it. I raised my hand and told teacher about my outstanding algorithm. Teacher just smiled and smiled...

After class, my teacher gave me a new problem and he wanted me solve it in 1 minute, too. If we know three parameters N, M, K, and two equations:

1. SUM (A1, A2, ..., Ai, Ai+1,..., AK) = N 

2. LCM (A1, A2, ..., Ai, Ai+1,..., AK) = M

Can you calculate how many kinds of solutions are there for Ai (Ai are all positive numbers). I began to roll cold sweat but teacher just smiled and smiled.

Can you solve this problem in 1 minute?

Input

There are multiple test cases.

Each test case contains three integers N, M, K. (1 ≤ N, M ≤ 1,000, 1 ≤ K ≤ 100)

Output

For each test case, output an integer indicating the number of solution modulo 1,000,000,007(1e9 + 7).

You can get more details in the sample and hint below.

Sample Input

4 2 23 2 2

Sample Output

12

Hint

The first test case: the only solution is (2, 2).

The second test case: the solution are (1, 2) and (2, 1).

这题时间卡的真紧啊!

 

#include 
#include
#include
#include
using namespace std;#define MAXN 1005#define mod 1000000007int lca[MAXN][MAXN],dp[2][MAXN][MAXN],vec[MAXN];int gcd(int a,int b){ if(a==0)return b; return gcd(b%a,a);}int main(){ int n,m,k,i,j,now,no,k1,j1,ans,ii; for(i=1;i<=1000;i++) for(j=i;j<=1000;j++) lca[j][i]=lca[i][j]=i/gcd(i,j)*j; while(scanf("%d%d%d",&n,&m,&no)!=EOF) { now=0; //memset(dp,0,sizeof(dp)); ans=0; vec[ans++]=1; for(i=2;i<=m;i++) { if(m%i==0) vec[ans++]=i; } for(ii=0;ii<=n;ii++) for(j=0;j
n) break; k1=lca[k][j1]; if(k1>m||m%k1!=0) continue; dp[now][j1+j][k1]+=dp[now^1][j][k]; dp[now][j1+j][k1]%=mod; } } } printf("%d\n",dp[now][n][m]%mod); } return 0;}

 

 

转载地址:http://dcwua.baihongyu.com/

你可能感兴趣的文章
售前工程师的成长---一个老员工的经验之谈
查看>>
Get到的优秀博客网址
查看>>
dubbo
查看>>
【Git入门之四】操作项目
查看>>
老男孩教育每日一题-第107天-简述你对***的理解,常见的有哪几种?
查看>>
Python学习--time
查看>>
在OSCHINA上的第一篇博文,以后好好学习吧
查看>>
高利率时代的结局,任重道远,前途叵测
查看>>
Debian 6.05安装后乱码
查看>>
欢迎大家观看本人录制的51CTO精彩视频课程!
查看>>
IntelliJ IDEA中设置忽略@param注释中的参数与方法中的参数列表不一致的检查
查看>>
关于软件开发的一些感悟
查看>>
uva 10806
查看>>
纯CSS3绘制的黑色图标按钮组合
查看>>
Linux中环境变量文件及配置
查看>>
从0开始学Flutter
查看>>
mysql操作入门基础之对数据库和表的增删改查
查看>>
IIS负载均衡
查看>>
分布式事务,EventBus 解决方案:CAP【中文文档】
查看>>
Linux下的CPU性能瓶颈分析案例
查看>>