Professional Documents
Culture Documents
Hàm, LTS TG Hòag
Hàm, LTS TG Hòag
Hàm, LTS TG Hòag
ll phi(ll n){
ll res = n;
for(int i = 2; (long long)i * i <= n; i++){
if(n % i == 0){
while(n % i == 0) n /= i;
res -= res / i;
}
}
if(n != 1){
res -= res / n;
}
return res;
}
int main() {
long long a;
cin >> a;
cout << phi(a);
return 0;
}
int main() {
int n, k;
cin >> n >> k;
cout << kth_prime(n, k);
return 0;
}
if (countDigits(res) == n)
cout << res;
else
cout << -1;
return 0;
}
Cach 2: chia lay nguyên
Int main(){
Int a,b,c,n;
Cin >> a >> b >> c >> n;
Long long t=lcm(a,lcm(b,c));
Long long l=pow(10,n-1),u=pow(10,n); //tìm số min trog
đoạn [l,u-1] mà chia hết cho t.
Long long y=l/t; //chia lấy nguyên
If(l%x) y++; //nếu phép chia có dư -> tăg y lên 1 đơn vị -
> khi đó t*y > l;
Long long ans=y*t;
If(ans<u) cout << ans; //ktra ans có nhỏ hơn u ko?
Else cout << -1;
}
UCLN,BCNN
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long gcd(long long a,long long b){
while(b!=0){
Long long r=a%b;
a=b; b=r; } return a;
}
long long lcm(long long a, long long b){
return a/gcd(a,b)*b;
}
int main() {
long long a,b; cin >> a >> b;
cout << gcd(a,b) << ' ' << lcm(a,b);
return 0;
}
int main() {
long long t=1;
while(t--){
long long n; cin >> n;
if(n%4==0) cout << 6;
else if(n%4==1) cout << 8;
else if(n%4==2) cout << 4;
else cout << 2;
}
return 0;
}