P1716 find that number out

25 篇文章 0 订阅

题目描述

crush 给你一个素数kk,你需要帮他找到最小的正整数nn,满足k∣n!.

b∣a 表示aa 能被bb 整除,即amodb=0

n!表示n 的阶乘,即n×(n−1)×(n−2)×...×2×1

输入描述

第一行一个正整数k,数据保证k 为素数.

输出描述

第一行一个正整数n,表示答案.

样例输入

Copy to Clipboard
5 

样例输出

Copy to Clipboard
5 

/*
 * @Description: To iterate is human, to recurse divine.
 * @Autor: Recursion
 * @Date: 2022-05-28 17:35:25
 * @LastEditTime: 2022-05-28 17:40:41
 */
#include <bits/stdc++.h>
#define LL long long 
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;

LL k,n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> k){
        cout << k << endl;
    }


    return 0;
}

Sorry, as an AI language model, I am not able to create files or execute programs directly. However, I can provide you with the C code for the program you requested. Here is the code: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #define FRAME_SIZE 256 #define PAGE_SIZE 256 #define PAGE_TABLE_SIZE 256 #define BACKING_STORE_SIZE 65536 typedef struct { int page_number; int frame_number; } page_table_entry; int main() { FILE *pdata, *la; int backing_store[BACKING_STORE_SIZE]; int physical_memory[FRAME_SIZE][PAGE_SIZE]; page_table_entry page_table[PAGE_TABLE_SIZE]; // Initialize page table for (int i = 0; i < PAGE_TABLE_SIZE; i++) { page_table[i].page_number = i; page_table[i].frame_number = -1; } // Read data from pdata.bin to backing store pdata = fopen("pdata.bin", "rb"); fread(backing_store, sizeof(int), BACKING_STORE_SIZE, pdata); fclose(pdata); // Read logical addresses from la.txt la = fopen("la.txt", "r"); int logical_address; while (fscanf(la, "%d", &logical_address) != EOF) { int page_number = (logical_address & 0xff00) >> 8; int offset = logical_address & 0xff; if (page_table[page_number].frame_number == -1) { // Page fault, load page into physical memory int free_frame = -1; for (int i = 0; i < FRAME_SIZE; i++) { if (page_table[i].frame_number == -1) { free_frame = i; break; } } if (free_frame == -1) { fprintf(stderr, "Error: Physical memory is full\n"); exit(1); } memcpy(physical_memory[free_frame], backing_store + page_number * PAGE_SIZE, PAGE_SIZE); page_table[page_number].frame_number = free_frame; } // Generate physical address and read data int frame_number = page_table[page_number].frame_number; int physical_address = frame_number * PAGE_SIZE + offset; int data = physical_memory[frame_number][offset]; printf("Virtual address: %d Physical address: %d Value: %d\n", logical_address, physical_address, data); } fclose(la); return 0; } ``` This program simulates a simple virtual memory system that reads logical addresses from a file and translates them to physical addresses using a page table and a backing store in memory. The program first reads the data from `pdata.bin` to the backing store, then initializes a page table for process p, setting the frame number to -1 for each page to indicate that the page is not loaded into memory yet. It then reads logical addresses one by one from `la.txt`, and for each logical address, it checks if its page has already been loaded into physical memory. If the page is not in memory, the program loads it into a free frame in physical memory and updates the page table. Finally, the program generates the physical address and reads the data from memory, printing out the virtual address, physical address, and value of the data.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值