ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213027 | #3824. 最大公约数 | 18112606231 | 30 | 293ms | 1152kb | C++11 | 1.2kb | 2024-11-03 12:34:47 | 2024-11-03 13:02:06 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
int t,n, ans;
int phi(int x)
{
int res = x;
for (int i = 2; i <= x / i; i++)
{
if (x % i == 0)
{
res = res / i * (i - 1);
while (x % i == 0)
x /= i;
}
}
if (x > 1)
res = res / x * (x - 1);
return res;
}
void baoli(){
unsigned long long ans = 0;
int xishu = -1;
for(int i = 0 ; i <= n ; i++){
ans += (xishu *= -1) * __gcd(n, i);
}
printf("%lld\n",ans);
}
signed main()
{
t = read();
while (t--)
{
n = read();
/*for (int i = 1; i <= n / i; i++)
{
if (n % i == 0)
{
ans += i * phi(n / i);
if (n / i != i)
ans += (n / i) * phi(i);
}
}
printf("%lld\n", ans);*/
baoli();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 102ms
memory: 1148kb
input:
10 54926 90288 81440 67894 64722 61170 95256 94752 59904 98368
output:
162827 2104272 813680 202699 453747 244635 1775844 2125872 1269504 1247488
result:
ok 10 lines
Test #2:
score: 10
Accepted
time: 100ms
memory: 1152kb
input:
10 64000 76328 56400 75540 89808 72566 71682 57048 89460 99316
output:
1043200 903284 1023600 528600 688368 212091 301307 342228 1475208 468152
result:
ok 10 lines
Test #3:
score: 10
Accepted
time: 91ms
memory: 1148kb
input:
10 80310 74048 68070 50202 75380 59528 84544 84640 55440 61056
output:
321195 923648 272235 167319 346712 391028 591616 1194160 1706544 1048896
result:
ok 10 lines
Test #4:
score: 0
Time Limit Exceeded
input:
10 449813415219 238127986797 141941948583 570931177507 599551449147 107803513771 877967309187 390005...
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
10 10384276147 991130530443 376705130467 176660198029 71835888101 243351181691 106856013219 60580750...
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
10 873655567624 887745378432 579208100112 627322249728 674458211840 831871918080 671762267568 957053...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
10 588091392000 526120252000 785151270000 960505337304 890742975972 536233040000 611974995856 541092...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
10 884417667840 852117801984 871881667200 551138972160 644606815160 907614111040 557989228800 917485...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
10 830832396800 727006448672 696814829568 608595958080 765299682306 822293683200 990128124000 833599...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
10 792907836240 851587632744 993304166400 507384285600 873921498624 866248782720 697501279180 813957...