数论练习题

1.Divisor SummationSPOJ - DIVSUM

题意:求n的所有因子和    (O(N*logN))调和级别

#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define eps 1e-8
#define zero(x) (((x) > 0 ? (x) : -(x)) < eps)
using namespace std;
const int maxn = 1e6 + 10;
int n, m,d[maxn];

signed main()
{
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    //  ios::sync_with_stdio(false);
    for (int i = 1; i <= 500000; i++)
    {
        for (int j = 2 * i; j <= 500000; j += i)
        {
            d[j] += i;
        }
    }
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        cout << d[n] << endl;
    }
    return 0;
}

2.GCD LCM

UVA - 11388

题意:给出LCM与GCD,求最小符合的数a,b

 由GCD(a,b) | LCM(a,b)

#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define eps 1e-8
#define zero(x) (((x) > 0 ? (x) : -(x)) < eps)
using namespace std;
const int maxn = 1e6 + 10;
int n, m;

signed main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int a, b;
        cin >> a >> b;
        if (b % a != 0)
            cout << -1 << endl;
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值