【__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