zoukankan      html  css  js  c++  java
  • 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 n2n3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m2m3m 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
    ",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
    ",k/kill(n,m));
    38     return 0;
    39 }
    40 */
  • 相关阅读:
    Orcle数据库查询练习复习:二
    Orcle数据库查询练习复习:一
    Xamarin.Android 入门之:xamarin使用webserver和html交互
    Xamarin.Android 入门之:Listview和adapter
    Xamarin.Android 入门之:Android的生命周期
    Xamarin.Android 入门之:Android API版本设置
    Xamarin.Android 入门之:Xamarin快速入门
    阶段01Java基础day16集合框架02
    阶段01Java基础day13常见对象02
    阶段01Java基础day10面向对象05
  • 原文地址:https://www.cnblogs.com/z-712/p/7324420.html
Copyright © 2011-2022 走看看