codeforces 371B
来源:互联网 发布:js添加display none 编辑:程序博客网 时间:2024/06/16 04:32
思路:将每个数都除以2,3,5直到不能再除,如果最后数不一样就返回-1,一样就根据除的次数返回,也可以先求最大公约数,然后看剩下的是不是能被2,3,5除尽。#include<iostream>#include<cstring>using namespace std;int ans;int x[5],y[5];int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b);}bool cnt(int *num,int a){ while(a%5==0) a/=5,num[2]++; while(a%3==0) a/=3,num[1]++; while(a%2==0) a/=2,num[0]++; if(a!=1) return false; return true;}int main(){ int a,b; cin>>a>>b; if(a==b) { cout<<0<<endl; return 0; } int g=gcd(a,b); a/=g; b/=g; memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); bool flag=true; int ans=0; if(cnt(x,a)) ans+=x[0]+x[1]+x[2]; else flag=false; if(cnt(y,b)) ans+=y[0]+y[1]+y[2]; else flag=false; if(flag) cout<<ans<<endl; else cout<<-1<<endl; return 0;}
0 0
- codeforces日记 371b
- codeforces 371B
- codeforces-371 B#
- Codeforces 371 A,B,C
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- codeforces 371B - Fox Dividing Cheese
- Codeforces 371B - Filya and Homework(思维)
- codeforces#371 B.Filya and Homework
- 狐狸分奶酪(codeforces 371b)
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- 华为嵌入式笔试题
- RabbitMQ消息队列的小伙伴: ProtoBuf(Google Protocol Buffer)
- kobject和kset
- java多线程实现任务超时监听
- Android设备驱动之——V4L2
- codeforces 371B
- 黑马程序员_异常
- 大端小端区别、Union和Struct的内存分配
- trie树,儿子兄弟表示法+uva11732
- 禁止 UltraEdit 自动检查更新的方法
- 观察者模式中怎样建立被观察者拥有多个观察者
- 嵌入式软件笔试题 (c语言版)
- 总线设备驱动模型
- [USACO Section 2.1] Sorting a Three-Valued Sequence (求排序最少交换次数)