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 */
  • 相关阅读:
    AWS EC2服务器的HTTPS负载均衡器配置过程
    大数据技术Hadoop笔试题
    网上找的hadoop面试题目及答案
    360全景图three.js
    360全景图three.js与Photo-Sphere-Viewer-master 3D全景浏览开发
    @font-face 字体
    scss语法
    6.事件
    5.回调函数
    4.querystring属性
  • 原文地址:https://www.cnblogs.com/z-712/p/7324420.html
Copyright © 2011-2022 走看看