結果
| 問題 | No.2249 GCDistance | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-03-17 22:48:20 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 799 ms / 5,000 ms | 
| コード長 | 1,210 bytes | 
| コンパイル時間 | 637 ms | 
| コンパイル使用メモリ | 87,212 KB | 
| 最終ジャッジ日時 | 2025-02-11 13:55:13 | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 10 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     int tc; scanf("%d", &tc);
      |             ~~~~~^~~~~~~~~~~
main.cpp:31:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     for (i=0; i<tc; i++) scanf("%d", &ts[i]);
      |                          ~~~~~^~~~~~~~~~~~~~
            
            ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
LL ss[10000004];
char pmk[10000004];
LL fy[10000004];
#define MAXN 10000000
int ts[200004];
int main() {
    int n, i, j, p, c, cc, mx;
    LL r, x;
    int tc; scanf("%d", &tc);
    for (i=0; i<tc; i++) scanf("%d", &ts[i]);
    mx=0; for (i=0; i<tc; i++) mx=max(mx, ts[i]);
    memset(pmk, 0, mx+1);
    for (i=0; i<=mx; i++) fy[i]=1;
    for (i=2; i<=mx; i++) if (pmk[i]==0) {
        p=i;
        c=0;
        for (j=i; j<=mx; j+=i) {
            pmk[j]=1;
            c++;
            x=p-1; cc=c; while((cc%p)==0) { cc/=p; x*=p; }
            fy[j]*=x;
        }
    }
    ss[0]=0; ss[1]=0;
    for (i=2; i<=MAXN; i++) ss[i]=ss[i-1]+fy[i];
    for (i=0; i<tc; i++) {
        n=ts[i];
    // while(tc) { tc--;
        // scanf("%d", &n);
        // 0--n-1
        r = n; r*=n-1; r/=2;
        r+=(r-ss[n]);
        printf("%lld\n", r);
    }
    return 0;
}
            
            
            
        