__int128 类型无标准 I/O 支持,需手动实现读写函数。

__int128 类型知识点】
☀ 在提高+、省选及NOI赛题中,经常会遇到
超级大的输入输出,此时若使用 C/C++ 中的宏指令 #define int __int128 将代码中所有的 int 类型替换为 __int128 类型,需配合 signed main(){ } 使用,否则将会导致使用 int main(){ } 时的返回值类型错误。

☀ 但是,
__int128 类型无标准 I/O 支持,无法直接使用 cin / cout / scanf / printf,需手动实现读写函数。

int read() { //fast read
    int x=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') { //!isdigit(c)
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0' && c<='9') { //isdigit(c)
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}

void print(int x) {
    if(x<0) putchar('-'), x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}


【应用实例】
应用
__int128 类型的一个实例,详见:
洛谷 P2303:https://blog.csdn.net/hnjzsyjyj/article/details/148128514

#include <bits/stdc++.h>
#define int __int128
using namespace std;
 
int oula_phi(int x) {
    int ans=x;
    for(int i=2; i*i<=x; i++) {
        if(x%i==0) {
            ans=ans/i*(i-1);
            while(x%i==0) x/=i;
        }
    }
    if(x>1) ans=ans/x*(x-1);
    return ans;
}
 
int read() { //fast read
    int x=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') { //!isdigit(c)
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0' && c<='9') { //isdigit(c)
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
 
void print(int x) {
    if(x<0) putchar('-'), x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
 
signed main() {
    int n,cnt=0;
    n=read();
    for(int i=1; i*i<=n; i++) {
        if(n%i==0) {
            cnt+=i*oula_phi(n/i);
            if(i!=n/i) cnt+=(n/i)*oula_phi(i);
        }
    }
    print(cnt);
 
    return 0;
}
 
/*
in:6
out:15
*/




【参考文献】
https://blog.csdn.net/hnjzsyjyj/article/details/120131534
https://www.luogu.com.cn/problem/P5091
https://www.luogu.com.cn/problem/P2568
https://www.luogu.com.cn/problem/P2303
https://blog.csdn.net/hnjzsyjyj/article/details/148128514

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值