Round #395 A. Taymyr is calling you(Div.2)

Comrade Dujikov is busy choosing artists for Timofey‘s birthday and is recieving calls from Taymyr from Ilia-alpinist.

Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1,?2,?...,?z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.

Input

The only string contains three integers — nm and z (1?≤?n,?m,?z?≤?104).

Output

Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.

Examples

input

1 1 10

output

10

input

1 2 5

output

2

input

2 3 9

output

1

Note

Taymyr is a place in the north of Russia.

In the first test the artists come each minute, as well as the calls, so we need to kill all of them.

In the second test we need to kill artists which come on the second and the fourth minutes.

In the third test — only the artist which comes on the sixth minute.

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 const int maxn=10005;
 6 int a[maxn];
 7 int main(){
 8     int n,m,k;
 9     while(~scanf("%d%d%d",&n,&m,&k)){
10      memset(a,0,sizeof(a));
11     int ans=0;
12      for(int i=n;i<=k;i=i+n)    //i=i+n
13       a[i]=1;
14      for(int i=m;i<=k;i=i+m)
15         if(a[i]==1)
16         ans++;
17     printf("%d\n",ans);
18     }
19     return 0;
20 }
21
22
23 /*
24 #include <iostream>
25 #include <stdio.h>
26 using namespace std;
27 int  gcd(int  a,int b){
28     return b?gcd(b,a%b):a;
29 }
30 int kill(int a,int b){
31 return a/gcd(a,b)*b;
32 }
33
34 int main(){
35         int n,m,k;
36         scanf("%d%d%d",&n,&m,&k);
37         printf("%d\n",k/kill(n,m));
38     return 0;
39 }
40 */
时间: 2024-10-10 22:30:04

Round #395 A. Taymyr is calling you(Div.2)的相关文章

Codeforces Round #395 (Div. 2)(未完)

2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; const int N=1e4+5; inline int read()

Codeforces Round #395 (Div. 2)

今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了. A. Taymyr is calling you 水题,问你在z范围内  两个序列  n,2*n,3*n......  和 m,2*m,3*m.....有多少个是一样的. #include<bits/stdc++.h> using namespace std; int n,m,z; int main() { cin>>n>>m>>z; int gcd=__gcd(n,m);

Codeforces Round #395 A

Taymyr is calling you 题意:给你n,m求不超过z的即是n的倍数又是m的倍数的树有多少个 思路:z/(n*m) *gcd(n,m)小学奥数题,或者直接暴力也可以 AC代码: #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "v

Codeforces Round #395 (Div. 2) C

题意 : 给出一颗树 每个点都有一个颜色 选一个点作为根节点 使它的子树各自纯色 我想到了缩点后check直径 当<=3的时候可能有解 12必定有解 3的时候需要check直径中点的组成点里是否有一个点连接了另外所有的点 如果有就是ans 没有就是no 这个方法是对了 不过比较麻烦..需要很多check 但是看div1的做法 有很棒的姿势用来解这个题 扫一下所有的边 如果两边的点颜色不一样 就增加一个连通分量数 这样可以很方便的算出有多少连通分量 同时记录这个点连着多少个其余的颜色(连通分量)

Codeforces Round #395 (Div. 2) D

Description One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, b

Codeforces Round #395 (Div. 2) 解题报告

年后恢复训练参加的第一场,表现的不是很好,必须要赶紧振作起来了啊. A.B题不再赘述. C题 不要被树的形式吓到,实际上不需要换根DFS,只需要看两顶点颜色不同的线段即可. 1 #include<stdio.h> 2 #include<bits/stdc++.h> 3 #include <iostream> 4 using namespace std; 5 typedef long long ll; 6 typedef unsigned long long ull; 7

【树形DP】Codeforces Round #395 (Div. 2) C. Timofey and a tree

先把1看作根. 预处理出f[i]表示以i为根的子树是什么颜色,如果是杂色的话,就是0. 然后从根节点开始转移,转移到某个子节点时,如果其子节点都是纯色,并且它上面的那一坨结点也是纯色,就输出解. 否则如果其上面的一坨是纯色,并且其子节点有且只有一个杂色的时候,就递归处理该子节点. #include<cstdio> #include<cstdlib> using namespace std; #define N 100050 int v[N<<1],first[N],ne

Codeforces Round #395 C. Timofey and a tree

package codeforces; import java.util.*; public class CodeForces_764C_Timofey_and_a_tree { static final int N=(int) (2e5+10); @SuppressWarnings("unchecked") static ArrayList<Integer> a[]=new ArrayList[N]; static int book[]=new int[N]; stati

Codeforces Round #395 B

Timofey and cubes 题意: 思路:第奇数位数都没有改变位置,偶数位都与n-i+1调换了位置 AC代码: #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set"