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 */
  • 相关阅读:
    美国独立电影人制作的纪录片《南京梦魇——南京大屠杀》
    我的黑莓电子书阅读解决方案
    NativeExcel 破解笔记
    右键刷新弹出网页广告的解决办法
    可恶的硬件故障(已解决)
    XP系统无法出现关机界面的解决一例
    任务栏无任务显示的问题
    centos 删除指定文件之外的其他文件
    Canvas中的save方法和restore方法
    博弈论取石子问题
  • 原文地址:https://www.cnblogs.com/z-712/p/7324420.html
Copyright © 2011-2022 走看看