Codeforces Round #395 (Div. 2) - A

 

 

题目链接:http://codeforces.com/contest/764/problem/A

题意:有两个人,第一个人每n分钟到达一次目的地,第二个人每m分钟到达一次目的地,现在给定一个时间z问在z这个时间范围内两人相遇的次数。

思路:由于z,n,m的范围比较小。所以直接开个数组暴力模拟就好了。  更简单的其实答案就是z/lcm(n,m)

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef long long int LL;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int MAXN = 1e4 + 10;
int v[MAXN];
int main(){
//#ifdef kirito
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
//    int start = clock();
    int n,m,z;
    while (~scanf("%d%d%d", &n,&m,&z)){
        memset(v, 0, sizeof(v));
        for (int i = 1; i*n <= z; i++){
            v[i*n]++;
        }
        int ans = 0;
        for (int i = 1; i*m <= z; i++){
            if (v[i*m] > 0){
                ans++;
            }
        }
        printf("%d\n", ans);
    }
//#ifdef LOCAL_TIME
//    cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
    return 0;
}

 

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef long long int LL;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int MAXN = 1e5 + 10;
int gcd(int x, int y){
    return y==0? x : gcd(y, x%y);
}
int lcm(int x, int y){
    return x*y / gcd(x, y);
}
int main(){
//#ifdef kirito
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
//    int start = clock();
    int n,m,z;
    while (~scanf("%d%d%d", &n,&m,&z)){
        printf("%d\n", z / lcm(n, m));
    }
//#ifdef LOCAL_TIME
//    cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
    return 0;
}

 

posted @ 2017-02-03 21:21  キリト  阅读(139)  评论(0编辑  收藏  举报