Codeforces_340A_The Wall(简单题)
来源:互联网 发布:初中英语单词大全软件 编辑:程序博客网 时间:2024/05/06 12:24
题型:(数论)
题意:
两个人涂板砖,从第一块涂起,甲每隔x块涂一个,乙每隔y块涂一个。对于给出的区间[a,b],问区间内有几块板砖都被他俩涂过。
分析:
只有x和y的最小公倍数的倍数板砖才会被涂上两种颜色,所以就找到a后面的第一个lcm(x,y)的倍数h,然后答案即为:
ans = (b-a)/lcm(x,y) + 1 ,(h<=b)
ans = 0 ,(h>b)
代码:
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using namespace std;int gcd(int a,int b){ return b ? gcd(b,a%b) : a;}int lcm(int a,int b){ return a / gcd(a,b) * b;}int main(){ int x,y,a,b; while(~scanf("%d%d%d%d",&x,&y,&a,&b)){ int d = lcm(x,y); bool flag = true; int ans; while(1){ if(a%d==0){ break; } a++; if(a>b){ flag = false; break; } } if(!flag){ printf("0\n"); } else{ ans=(b-a)/d; ans++; printf("%d\n",ans); } } return 0;}
- Codeforces_340A_The Wall(简单题)
- 11040 - Add bricks in the wall(简单题)
- POJ1113 wall 简单凸包
- HDU1348 Wall 【简单凸包】
- wall
- Wall
- Wall
- poj 1113 wall 简单的凸包
- POJ 1113 Wall 包凸入门题
- hdu 1348 Wall 凸包模板题
- poj 1113 Wall 凸包模板题
- hdu2124--Repair the Wall(贪心水题)
- HDOJ 1348 Wall (凸包模板题)
- POJ 1113 Wall 凸包(模板题)
- hdu1348 Wall(凸包模板题)
- 计算几何:极角排序(poj 2007 Scrambled Polygon)与简单凸包(poj 1113 Wall)
- hdu 1348 Wall(凸包模板题 Graham)
- HDU 1348 Wall(凸包模板题)
- grails的findBy的使用和密码非明文显示
- try、catch、finally巧遇return
- java 传值 常量池 构造函数 String (札记)
- Failed to access the USB subsystem.VirtualBox is not currently allowed to access USB devices...
- 算法 计算1-1/x+1/x*x-1/x*x*x……
- Codeforces_340A_The Wall(简单题)
- 程序锁的核心基本原理
- 学习水平方向进度条的方法
- junit批量测试
- kiki's game
- jsp 及 servlet 读写UTF-8 txt 乱码 解决方法
- ffmpeg,Stagefright 的时间管理及a/v同步
- 梦想的启航,那些年,那些书
- 【心情日记】从这里开始吧