結果
| 問題 | 
                            No.300 平方数
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tetsuzuki1115
                         | 
                    
| 提出日時 | 2017-09-29 08:32:25 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 836 bytes | 
| コンパイル時間 | 605 ms | 
| コンパイル使用メモリ | 79,056 KB | 
| 実行使用メモリ | 11,232 KB | 
| 最終ジャッジ日時 | 2024-11-15 19:35:41 | 
| 合計ジャッジ時間 | 2,096 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 WA * 7 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:17: warning: iteration 999998 invokes undefined behavior [-Waggressive-loop-optimizations]
   43 |         if ( A[i]%2 ) { ans *= i; }
      |              ~~~^
main.cpp:42:30: note: within this loop
   42 |     for ( long long i = 2; i <= 1000000; i++ ) {
      |                            ~~^~~~~~~~~~
            
            ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
long long MOD = 1000000007;
long long A[1000000] = {0};
int main() {
    
    long long X;
    cin >> X;
    
    long long x = X;
    
    for ( long long i = 2; i*i <= x; i++ ) {
        
        int j = 0;
        while ( X%i == 0 ) {
            X /= i;
            j++;
        }
        A[i] = j;
        
        if ( X == 1 ) { break; }
    }
    if ( X != 1 ) { cout << x << endl; return 0; }
    
    long long ans = 1;
    for ( long long i = 2; i <= 1000000; i++ ) {
        if ( A[i]%2 ) { ans *= i; }
    } 
    cout << ans << endl;
    
    
    return 0;
}
            
            
            
        
            
tetsuzuki1115