https://codeforces.com/contest/1525/problem/A

 

Problem - A - Codeforces

 

codeforces.com

 

 

[난이도] Div.2
[유형] 수학

[풀이]
K와 100-K의 최대공약수를 구한 뒤 100을 최대공약수로 나눠주면 된다.

 

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
 
int t,k;
 
int gcd(int a,int b){
    if(a>b) swap(a,b);
 
    while(a>0){
        int c = b%a;
        b=a;
        a=c;
    }
 
    return b;
}
 
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&k);
        if(k==100){
            puts("1");
            continue;
        }
 
        int a = k;
        int b = 100-k;
        int g = gcd(a,b);
        printf("%d\n",a/g+b/g);
    }
}


https://github.com/has2/Problem-Solving/blob/master/codeforces/RoundEDU109-Div.2/A.cpp

+ Recent posts