結果
| 問題 | No.1262 グラフを作ろう! | 
| コンテスト | |
| ユーザー |  沙耶花 | 
| 提出日時 | 2020-10-16 23:22:29 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 262 ms / 3,000 ms | 
| コード長 | 563 bytes | 
| コンパイル時間 | 2,057 ms | 
| コンパイル使用メモリ | 195,452 KB | 
| 最終ジャッジ日時 | 2025-01-15 09:45:42 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 96 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |                 scanf("%d",&A);
      |                 ~~~~~^~~~~~~~~
            
            ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int main(){	
	
	int N,M;
	cin>>N>>M;
	
	
	
	vector<long long> temp(N+1,0LL);
	
	for(int i=1;i<=N;i++){
		temp[i] += i;
		for(int j=i*2;j<=N;j+=i){
			temp[j] -= temp[i];
		}
	}
	
	vector<long long> ans(N+1,0);
	
	for(int i=1;i<=N;i++){
		for(int j=i;j<=N;j+=i){
			ans[j] += temp[i] * (j/i);
		}
	}
	
	long long Ans = 0LL;
	
	rep(i,M){
		int A;
		scanf("%d",&A);
		Ans += ans[A] - A;
	}
	
	cout<<Ans<<endl;
	
    return 0;
}
            
            
            
        